Ejemplo n.º 1
0
def train():
    notes = get_notes()
    # 得到所有不重复的音调数目
    num_pitch = len(set(notes))
    network_input, network_output = prepare_sequences(notes, num_pitch)
    model = network_model(network_input, num_pitch)
    # 输入,音符的数量,训练后的参数文件(训练的时候不用写)
    filepath = "weights1-{epoch:02d}-{loss:.4f}.hdf5"

    # 用checkpoint(检查点)文件在每一个Epoch结束时保存模型的参数
    # 不怕训练过程中丢失模型参数,当对loss损失满意的时候可以随时停止训练
    checkpoint = tf.keras.callbacks.ModelCheckpoint(
        filepath,  # 保存参数文件的路径
        monitor='loss',  # 衡量的标准
        verbose=0,  # 不用冗余模式
        save_best_only=True,  # 最近出现的用monitor衡量的最好的参数不会被覆盖
        mode='min'  # 关注的是loss的最小值
    )

    callbacks_list = [checkpoint]
    # callback = tf.keras.callbacks.LearningRateScheduler(scheduler)

    # 用fit方法来训练模型
    model.fit(network_input,
              network_output,
              epochs=80,
              batch_size=64,
              callbacks=callbacks_list)
Ejemplo n.º 2
0
def train():
    notes = utils.get_notes()

    # 得到所有不重复(因为用了 set)的音调数目
    num_pitch = len(set(notes))

    network_input, network_output = prepare_sequences(notes, num_pitch)

    model = network.network_model(network_input, num_pitch)

    filepath = "weights-{epoch:02d}-{loss:.4f}.hdf5"

    # 用 Checkpoint(检查点)文件在每一个 Epoch 结束时保存模型的参数(Weights)
    # 不怕训练过程中丢失模型参数。可以在我们对 Loss(损失)满意了的时候随时停止训练
    checkpoint = tf.keras.callbacks.ModelCheckpoint(
        filepath,  # 保存的文件路径
        monitor='loss',  # 监控的对象是 损失(loss)
        verbose=0,
        save_best_only=True,  # 不替换最近的数值最佳的监控对象的文件
        mode='min'  # 取损失最小的
    )
    callbacks_list = [checkpoint]

    # 用 fit 方法来训练模型
    model.fit(network_input,
              network_output,
              epochs=100,
              batch_size=64,
              callbacks=callbacks_list)
Ejemplo n.º 3
0
 def edit(self):
     self.show()
     print("EDIT entry (Leave fields blank for no changes)")
     self.title = utils.get_title(self.title)
     self.date = utils.get_date(self.date)
     self.time = utils.get_time(self.time)
     self.notes = utils.get_notes(self.notes)
     self.save()
Ejemplo n.º 4
0
 def add_task(cls):
     """Add new entry"""
     employee, _ = models.Employee.get_or_create(name=utils.get_name())
     task = models.Task.create(employee=employee,
                               title=utils.get_title(),
                               time=utils.get_time(),
                               notes=utils.get_notes())
     task.show()
     input("The entry has been added. Press enter to return to the menu")
Ejemplo n.º 5
0
 def edit(self):
     """
     Let the user to edit a task by being asked to edit any of their
     attributes. If any field is left blank, then it wont be changed.
     """
     self.show()
     print("EDIT entry (Leave fields blank for no changes)")
     self.title = utils.get_title(self.title)
     self.date = utils.get_date(self.date)
     self.time = utils.get_time(self.time)
     self.notes = utils.get_notes(self.notes)
Ejemplo n.º 6
0
 def __init__(self, **kwargs):
     """Initialize an instance of Task with needed attributes"""
     if kwargs:
         self.title = kwargs.get('Title')
         self.date = datetime.datetime.strptime(kwargs.get('Date'),
                                                '%d/%m/%Y').date()
         self.time = kwargs.get('Time')
         self.notes = kwargs.get('Notes')
     else:
         self.title = utils.get_title()
         self.date = utils.get_date()
         self.time = utils.get_time()
         self.notes = utils.get_notes()
Ejemplo n.º 7
0
def process():
    redis_db = get_db()
    mel_id = int(redis_db.get('mel_id'))
    filename = f'melody_{mel_id}.wav'
    with open('tmp/' + filename, 'wb') as file:
        file.write(request.data)

    melody = utils.get_notes(filename='tmp/' + filename, duration=10)
    if len(melody['notes']) != 0:
        melody = utils.fix_notes(melody)

        melody['id'] = mel_id
        melody['midi_filename'] = filename.split('.')[0] + '.mid'
        melody['proc_filename'] = filename.split('.')[0] + '_processed' + '.wav'

        redis_db.set(f'melody_{mel_id}', value=pickle.dumps(melody))
        redis_db.set('mel_id', (mel_id + 1))
    return redirect(url_for('index'))
Ejemplo n.º 8
0
 def test_get_notes(self, fake_input):
     fake_input.return_value = 'Test notes'
     result = utils.get_notes()
     self.assertEqual(result, 'Test notes')