def main(): X_train, y_train, inpz_train = load('data/train/merged.npz') X_test, y_test, inpz_test = load('data/test/merged.npz') # One-hot encoded Y_train = to_categorical(y_train, 2) Y_test = to_categorical(y_test, 2) Phi_sizes, F_sizes = (100, 100, 128), (100, 100, 100) efn = EFN(input_dim=2, Phi_sizes=Phi_sizes, F_sizes=F_sizes) efn.load_weights('ckpts_Apr06_134930/ckpt-40-val_acc-0.73.hdf5') ckpt_dir = strftime('ckpts_%b%d_%H%M%S') if not osp.isdir(ckpt_dir): os.makedirs(ckpt_dir) checkpoint_callback = ModelCheckpoint( ckpt_dir + '/ckpt-{epoch:02d}-val_acc-{val_acc:.3f}.hdf5', monitor='val_acc', verbose=1, save_best_only=False, mode='max') best_checkpoint_callback = ModelCheckpoint(ckpt_dir + '/ckpt-best.hdf5', monitor='val_acc', verbose=1, save_best_only=True, mode='max') efn.fit([X_train[:, :, 0], X_train[:, :, 1:]], Y_train, epochs=40, batch_size=64, validation_data=([X_test[:, :, 0], X_test[:, :, 1:]], Y_test), verbose=1, callbacks=[checkpoint_callback, best_checkpoint_callback])
print('Finished preprocessing') # do train/val/test split (z_train, z_val, z_test, p_train, p_val, p_test, Y_train, Y_val, Y_test) = data_split(X[:, :, 0], X[:, :, 1:], Y, val=val, test=test) print('Done train/val/test split') print('Model summary:') # build architecture efn = EFN(input_dim=2, Phi_sizes=Phi_sizes, F_sizes=F_sizes) # train model efn.fit([z_train, p_train], Y_train, epochs=num_epoch, batch_size=batch_size, validation_data=([z_val, p_val], Y_val), verbose=1) # get predictions on test data preds = efn.predict([z_test, p_test], batch_size=1000) # get ROC curve efn_fp, efn_tp, threshs = roc_curve(Y_test[:, 1], preds[:, 1]) # get area under the ROC curve auc = roc_auc_score(Y_test[:, 1], preds[:, 1]) print() print('EFN AUC:', auc) print()
f_sizes = (100, 100, 100) X, Y = load_data(2000000, 'final_efn_train') X = preprocess(X) Y = ef.utils.to_categorical(Y) (Z_train, Z_val, Z_test, P_train, P_val, P_test, Y_train, Y_val, Y_test) = split_data(X[:, :, 0], X[:, :, [1, 2]], Y, test_prop=1.0 / 5, val_prop=1.0 / 5) #adam = optimizers.Adam(lr=.005) efn = EFN(input_dim=P_train.shape[-1], Phi_sizes=phi_sizes, F_sizes=f_sizes) efn.fit([Z_train, P_train], Y_train, epochs=NUM_EPOCHS, batch_size=500, validation_data=([Z_val, P_val], Y_val), verbose=1) preds = efn.predict([Z_test, P_test], batch_size=1000) fpr, tpr, thresholds = roc_curve(Y_test[:, 1], preds[:, 1]) print('AUC: ' + str(auc(fpr, tpr))) plt.plot(tpr, 1 - fpr, '-', color='black', label='EFN') plt.show()
es = EarlyStopping(monitor='val_auc', mode='max', verbose=1, patience=20, restore_best_weights=True) #mc = ModelCheckpoint('best_model.h5', monitor='val_auc', mode='max', verbose=1, save_best_only=True) efn = EFN(input_dim=2, Phi_sizes=Phi_sizes, F_sizes=F_sizes, metrics=['acc', auc], Phi_l2_regs=5e-05, F_l2_regs=5e-05) history = efn.fit([z_train, p_train], Y_train, epochs=num_epoch, batch_size=batch_size, validation_data=([z_val, p_val], Y_val), verbose=1, callbacks=[es]) #dependencies = { # 'auc': tf.keras.metrics.AUC(name="auc") #} #saved_model = load_model('best_model.h5', custom_objects=dependencies) #preds = saved_model.predict([z_test, p_test], batch_size=1000) preds = efn.predict([z_test, p_test], batch_size=1000) auc = roc_auc_score(Y_test[:, 1], preds[:, 1]) print('EFN AUC:', auc) #save plots name = "{0}Jet_{1}Tag".format(args.nJets, args.nTags)