def gen_test_data(test): test_dir = '/content/test' test_bad_dir = test_dir + '/bad' test_good_dir = test_dir + '/good' save = None for idx in test: tif = TIF(idx) tif.gen_test(save=True, balance=True) save = tif return save.load_test_dir() # test data generator
lrs = [0.001, 0.0001, 0.00001] decays = [1e-5, 1e-6, 1e-7] for lr in lrs: for decay in decays: load_model_name=base+'/all-in-one-val'+'/model-epoch-'+str(i)+'-'+str(lr)+'-'+str(decay) model = loadModel(load_model_name+'.json', load_model_name+'.h5') sgd = optimizers.SGD(lr=lr, decay=decay, momentum=0.9, nesterov=True) model.compile(optimizer=sgd,loss='binary_crossentropy',metrics=['accuracy']) # AUC prediction, prediction_score, gt = view_result_auc(test_dir, model) y_pred = (np.transpose(prediction)) print(y_pred.shape) print(y_pred) y_true = gt print(y_true.shape) y_score = (np.transpose(prediction_score)) cm = confusion_matrix(y_true, y_pred) np.save('cm-fin-'+str(pas)+'-epoch-'+str(i)+'-'+str(lr)+'-'+str(decay), cm) plot_auc(y_true,y_score,'auc-fin-'+str(pas)+'-epoch-'+str(i)+'-'+str(lr)+'-'+str(decay)+'.png') # heatmap heat_prediction, heat_prediction_score = view_result_heatmap(TIF('078'), model) plt.imsave('heatmap_prediction-fin-'+str(pas)+'.png',1-np.transpose(heat_prediction)) print('done')
#timestamp = str(int(time.time())) timestamp = 'permute' os.system('mkdir '+'permute') base='/root/test2/' number_of_pass = 10 model = initiate_model(new=True, load_model_name='') epoch = 1 batch_size= 32 for pas in range(number_of_pass): random.shuffle(train_val_id) print("current pass---------", pas) for tif_id in train_val_id: tif = TIF(tif_id) train(model,tif,epoch,batch_size) model_name=base+timestamp+'/model-pass-'+str(pas+1) # save model to file saveModel(model, model_name)