print('epoch %d end at %s' % (epoch, str(end))) print('epoch %d train loss: %f' % (epoch, train_loss)) print('epoch %d dev loss: %f' % (epoch, dev_loss)) print('epoch %d dev accuracy: %f' % (epoch, epcoh_accuracy)) print('best epoch now: %d\n' % best_epoch) log.write('epoch %d end at %s\n' % (epoch, str(end))) log.write('epoch %d train loss: %f\n' % (epoch, train_loss)) log.write('epoch %d dev loss: %f\n' % (epoch, dev_loss)) log.write('epoch %d dev accuracy: %f\n' % (epoch, epcoh_accuracy)) log.write('best epoch now: %d\n\n' % best_epoch) end_time = datetime.now() print('train end at %s\n' % str(end_time)) log.write('train end at %s\n\n' % str(end_time)) timedelta = end_time - start_time print('train cost time: %s\n' % str(timedelta)) print('best epoch last: %d\n' % best_epoch) log.write('train cost time: %s\n\n' % str(timedelta)) log.write('best epoch last: %d\n\n' % best_epoch) plot.plot_loss(all_train_loss, all_dev_loss, folder_path=folder_path, title='%s' % model_name) plot.plot_accuracy(all_dev_accuracy, folder_path=folder_path, title='%s' % model_name)
train_y = np.load("output/train_anno.npy") train_names = np.load("output/train_names.npy") for name in runs[:1]: feature_type = name.split('_')[0] test_x = np.load("output/val_{}.npy".format(feature_type)) train_x = np.load("output/train_{}.npy".format(feature_type)) num_train, input_dim = train_x.shape _, output_dim = train_y.shape if TRAIN: loss_hist = simple_nn.train(input_dim, output_dim, train_x, train_y, test_x, test_y, name) plot.plot_loss(loss_hist, name) model = simple_nn.load(name) # make predictions on the test data train_loss = model.evaluate(train_x, train_y, verbose=0) val_loss = model.evaluate(test_x, test_y, verbose=0) print("{} - train: {}, val {}".format(model.metrics_names, train_loss, val_loss)) with open('logs/nn_losses.txt', 'a') as f: f.write('{} {} {} {}\n'.format(int(time.time()), name, train_loss, val_loss)) ''' print("[INFO] predicting...") preds = model.predict(test_x) evaluate.evaluate_point_normal(test_y, preds)