y_train2,
                    epochs=1,
                    batch_size=batch_size,
                    verbose=1,
                    shuffle=False,
                    validation_data=(x_train, y_train),
                    callbacks=[early_stopping, checkpointer, tensorboard])
# history = model.fit(x_train,y_train,epochs=max_epoch,batch_size=batch_size,verbose=1,shuffle=True,validation_data=(x_val, y_val),
#                     callbacks=[early_stopping,checkpointer,tensorboard])
# print('Fisrt stage finished, loss is stable')
#
#
pf_min = 6
pf_max = 8

pf_test = LambdaCallback(on_batch_end=lambda batch, logs: utils.get_pf(
    x_val, y_val, val_SNRs, model, batch, pf_min=pf_min, pf_max=pf_max))
print('Start second stage, trade-off metrics')
# model = load_model(best_model_path)
# model.fit(x_train,y_train,epochs=max_epoch,batch_size=batch_size,verbose=1,shuffle=False,
#           callbacks=[pf_test])
model.fit(x_train,
          y_train,
          epochs=max_epoch,
          batch_size=200,
          verbose=1,
          shuffle=True,
          callbacks=[pf_test])
#
if model.stop_training or True:
    # save results
    model.save('result/models/DetectNet/' + str(sample_length) + '/final.h5')
Ejemplo n.º 2
0
                                dense_units)

        history = model.fit(
            x_train,
            y_train,
            epochs=max_epoch,
            batch_size=batch_size,
            verbose=1,
            shuffle=True,
            validation_data=(x_val, y_val),
            callbacks=[early_stopping, checkpointer, tensorboard])
        print('Fisrt stage finished, loss is stable')

        pf_min = 4.0
        pf_max = 10
        pf_test = LambdaCallback(on_epoch_end=lambda epoch, logs: utils.get_pf(
            x_val, y_val, val_SNRs, model, epoch, pf_min, pf_max))

        print('Start second stage, trade-off metrics')
        model = load_model(best_model_path)
        model.fit(x_train,
                  y_train,
                  epochs=max_epoch,
                  batch_size=batch_size,
                  verbose=1,
                  shuffle=True,
                  callbacks=[pf_test])

        if model.stop_training:
            # save results
            model.save('result/models/DetectNet/' + str(sample_length) + '/' +
                       str(mod_name) + 'final.h5')
Ejemplo n.º 3
0
co_x_train = softmax_dataset[:int(total_group*0.6)]
co_y_train = softmax_labelset[:int(total_group*0.6)]
co_x_val = softmax_dataset[int(total_group*0.6):int(total_group*0.8)]
co_y_val = softmax_labelset[int(total_group*0.6):int(total_group*0.8)]
co_x_test = softmax_dataset[int(total_group*0.8):]
co_y_test = softmax_labelset[int(total_group*0.8):]
val_SNRs = SNR[int(total_group*0.6):int(total_group*0.8)]
test_SNRs = SNR[int(total_group*0.8):]

input_shape = (nodes,2)
model_co = utils.SoftCombinationNet(lr,input_shape,drop_ratio)

early_stopping = EarlyStopping(monitor='val_loss',patience=patience)
best_model_path = 'result/models/SoftCombinationNet/'+str(sample_length)+'/'+str(mod_name)+"_"+str(nodes) +'best.h5'
checkpointer = ModelCheckpoint(best_model_path,verbose=1,save_best_only=True)
model_co.fit(co_x_train,co_y_train,epochs=max_epoch,batch_size=batch_size,verbose=1,shuffle=True,
             validation_data=(co_x_val, co_y_val),
             callbacks=[early_stopping,checkpointer])  

#%%
model_co = load_model(best_model_path)
pf_min = 1.5
pf_max = 2.5
pf_test = LambdaCallback(
    on_epoch_end=lambda epoch, 
    logs: utils.get_pf(co_x_val,co_y_val,val_SNRs,model_co,epoch,pf_min,pf_max))
model_co.fit(co_x_train,co_y_train,epochs=max_epoch,batch_size=batch_size,verbose=1,shuffle=True,
             callbacks=[pf_test])

utils.performance_evaluation('result/xls/SoftCombinationNet/'+str(sample_length)+'/'+str(mod_name)+"_"+str(nodes) +'Pds_soft.xls',co_x_test,co_y_test,test_SNRs,model_co)