-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlearning.py
56 lines (50 loc) · 1.56 KB
/
learning.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from model.network import LeMoN
from time import time
from prefetch_generator import BackgroundGenerator
from telebot import TeleBot
from tools.train_utils import get_data, iterate_minibatches
import config
bot = TeleBot(config.telegram_token)
def send_log(message):
bot.send_message(config.channel, message)
send_log("Создаем модель...")
model = LeMoN()
send_log("Грузим данные...")
points, music = get_data("ok_dat.npy")
send_log("""Настраиваем параметры:
epoch = 100
batch_size = 1000
time_leght = 20
""")
epoch = 100
batch_size = 1000
time_length = 20
iterate_mini_set = {
"points": points,
"music": music,
"batch_size": batch_size,
"block_size": time_length
}
message = """Эпоха: {}
Время: {} H
Средняя ошибка(square error): {}"""
send_log("Тренируемся")
try:
for epoch in range(1, epoch+1):
n = 0
loss = 0
st = time()
for music_, shift, stp, delta_mov in BackgroundGenerator(iterate_minibatches(**iterate_mini_set)):
loss += model.train(music_.reshape((-1, time_length, 200)), shift.reshape((-1, 19, 38*3)),
stp, delta_mov.reshape((-1, 38*3)))
n += 1
t = time() - st
send_log(message.format(epoch, t, loss/(n*1.)))
send_log("Сохраняем веса")
try:
model.save()
except Exception as e:
send_log("Error when save: {}".format(e))
except Exception as e:
send_log("Error: {}".format(e))
send_log("!!!Готово!!!")