cRM2 = np.abs(F2) / np.abs(FM)
    cRM2[~np.isfinite(cRM2)] = 0
    cRM = np.zeros((1, 298, 257, 2, 2))
    cRM[0, :, :, :, 0] = cRM1
    cRM[0, :, :, :, 1] = cRM2
    print('shape of cRM should be (1,298,257,2,2):', cRM.shape)

    input_dim = (298, 257, 2)
    output_dim = (298, 257, 2, 2)
    filepath = "model-{epoch:02d}-{val_loss:.4f}.h5"
    checkpoint = ModelCheckpoint(filepath,
                                 monitor='val_loss',
                                 verbose=1,
                                 save_best_only=True,
                                 mode='min')
    model = model_AO.AO_model(2)

    # Note: added compile to bypass error
    adam = optimizers.Adam()
    model.compile(optimizer=adam, loss='mse')

    model.fit(FM,
              cRM,
              epochs=5,
              batch_size=2,
              validation_data=(FM, cRM),
              shuffle=False,
              callbacks=[TensorBoard(log_dir='./log'), checkpoint])

    pred_cRM = model.predict(FM)
Esempio n. 2
0
with open((database_dir_path + '/AV_log/AVdataset_train.txt'), 'r') as t:
    trainfile = t.readlines()
with open((database_dir_path + '/AV_log/AVdataset_val.txt'), 'r') as v:
    valfile = v.readlines()
# ///////////////////////////////////////////////////////// #

# the training steps
if RESTORE:
    latest_file = latest_file(path + '/')
    print("Restoring model from:", latest_file)
    loss = audio_loss(gamma=gamma_loss, beta=beta_loss, num_speaker=people_num)
    AO_model = load_model(latest_file, custom_objects={"loss_func": loss})
    info = latest_file.strip().split('-')
    initial_epoch = int(info[-2])
else:
    AO_model = AO.AO_model(people_num)

train_generator = AudioGenerator(trainfile,
                                 database_dir_path=database_dir_path,
                                 batch_size=batch_size,
                                 shuffle=True)
val_generator = AudioGenerator(valfile,
                               database_dir_path=database_dir_path,
                               batch_size=batch_size,
                               shuffle=True)

if NUM_GPU > 1:
    parallel_model = ModelMGPU(AO_model, NUM_GPU)
    adam = optimizers.Adam()
    loss = audio_loss(gamma=gamma_loss, beta=beta_loss, num_speaker=people_num)
    parallel_model.compile(loss=loss, optimizer=adam, metrics=['accuracy'])