if val_accuracy > best_accuracy: best_accuracy = val_accuracy best_epoch = epoch if model_path is not None: model.save_weights(model_path + '.npz') cPickle.dump(model, open(model_path + '.pkl', 'w')) print( 'epoch={epoch:05d}, iteration={iteration:05d}, loss={loss:.04f}, val_loss={val_loss:.04f}, val_acc={val_acc:.04f} best=[accuracy={best_accuracy:.04f} epoch={best_epoch:05d}]' .format(epoch=epoch, iteration=iteration, loss=train_loss, val_loss=val_loss, val_acc=val_accuracy, best_accuracy=best_accuracy, best_epoch=best_epoch)) iteration += 1 if iteration % len(train_files) == 0: epoch += 1 x_train, y_train = load_model_data(next(train_files_iter), args.data_name, args.target_name, n=args.n_train) if __name__ == '__main__': parser = modeling.parser.build_lasagne() sys.exit(main(parser.parse_args()))
x_validation, y_validation_one_hot = preprocessor.transform( x_validation, y_validation_one_hot) if isinstance(net, keras.models.Graph): train_data = marshaller.marshal( x_train, y_train_one_hot) validation_data = marshaller.marshal( x_validation, y_validation_one_hot) net.fit(train_data, shuffle=args.shuffle, nb_epoch=args.n_epochs, batch_size=model_cfg.batch_size, validation_data=validation_data, callbacks=callbacks, class_weight=class_weight, verbose=2 if args.log else 1) else: net.fit(x_train, y_train_one_hot, shuffle=args.shuffle, nb_epoch=args.n_epochs, batch_size=model_cfg.batch_size, show_accuracy=True, validation_data=(x_validation, y_validation_one_hot), callbacks=callbacks, class_weight=class_weight, verbose=2 if args.log else 1) if __name__ == '__main__': parser = modeling.parser.build_keras() sys.exit(main(parser.parse_args()))