def evaluate_transfer(): evaluation = {} for name in subjects: def transfer_filter(paths): return [path for path in paths if path.split("_-_")[1] == name] transfer_model = tf.keras.models.load_model( os.path.join( cwd, "output" "model_transfer_{}_{}_{}.h5".format(name, args.window, args.band))) single_eval = test_model(model=transfer_model, eval_location="", data_folder=data_folder, batch_size=args.batch, time_window=args.window, batch_equalizer=Default2EnvBatchEqualizer(), filters=[transfer_filter], save=False) evaluation[name] = single_eval[name] with open( "output/evaluation_transfer_{}_{}.json".format( args.window, args.band), "w") as fp: json.dump(evaluation, fp)
def evaluate(): parser = argparse.ArgumentParser(description='Evaluate the recurrent model') parser.add_argument('--window', '--w', metavar='TIME_WINDOW', type=int, help='size of window to train the model on', required=True) parser.add_argument('--batch', '--b', metavar='BATCH_SIZE', type=int, help='size of batch to use during training', required=True) parser.add_argument('--band', '--B', metavar='BAND', type=str, choices=['full', 'delta', 'theta', 'delta_theta'], help='which band(s) to use for testing', required=True) args = parser.parse_args() cwd = os.path.dirname(os.path.abspath(__file__)) root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) test_model(model=tf.keras.models.load_model(os.path.join(cwd, "output", "model_{}_{}.h5".format(args.window, args.band))), eval_location="output/evaluation_{}_{}.json".format(args.window, args.band), data_folder=os.path.join(root, "dataset", args.band), batch_size=args.batch, time_window=args.window, batch_equalizer=Default2EnvBatchEqualizer())
train_model( model=model, epochs=args.epochs, model_location=os.path.join( cwd, "output", "model_general_{}_{}_{}.h5".format(name, args.window, args.band)), log_location=os.path.join( cwd, "output", "training_general_{}_{}_{}.log".format(name, args.window, args.band)), data_folder=data_folder, batch_size=args.batch, time_window=args.window, batch_equalizer=Default2EnvBatchEqualizer(), filters=[subject_filter]) # Transfer learning model.get_layer(name="eeg_conv1d_space").trainable = False model.get_layer(name="eeg_bilstm").trainable = False model.get_layer(name="env_conv1d").trainable = False model.get_layer(name="env_lstm").trainable = False model.get_layer(name="sigmoid").trainable = False def transfer_filter(paths): return [path for path in paths if path.split("_-_")[1] == name] train_model(model=model, epochs=args.epochs, model_location=os.path.join(