val_err = 0 val_acc = 0 val_batches = 0 for batch in iterate_minibatches(x_validate, labels_validate, oneshot_indices_validate, oneshot_class, batch_size, shuffle=False): inputs, targets = batch print('\rValidation phase {:6.1f}%'.format(val_batches * batch_size / validate_size * 100), end="");sys.stdout.flush() err, acc = convnet.validate(inputs, targets) val_err += err val_acc += acc val_batches += 1 if( val_err < min_val_err ): min_val_err = val_err convnet.save_param_values(save_param_path) print('\rValidation phase {:6.1f}%'.format( 100)) # Print out results each epoch and write to outputfile print("Epoch {} of {} took {:.2f}s".format( epoch + 1, num_epochs, time.time() - start_time)) print(" training loss:\t\t{:.6f}".format(train_err / train_batches)) print(" validation loss:\t\t{:.6f}".format(val_err / val_batches)) print(" validation accuracy:\t\t{:.2f} %".format(val_acc / val_batches * 100)) fo1.write("%.6f;%.6f;%.6f;%.6f\n" % ( train_err / train_batches, val_err / val_batches, val_acc / val_batches, time.time() - start_time)) print() # Compute and print test error
excerpt = indices[start_idx:start_idx + batch_size] yield inputs[excerpt], targets[excerpt] base_dir_path = "/home/jasper/oneshot-gestures/" test_accuracies = [] load = load_class.load(size_ratio=1.0) # Load data x_validate, labels_validate, indices_validate = load.load_validation_set() x_train, labels_train, indices_train = load.load_training_set() x_test, labels_test, indices_test = load.load_testing_set() convnet = convnet.convnet(num_output_units=20) convnet.save_param_values("{}/default_param".format(base_dir_path)) for oneshot_class in xrange(20 ): print("Learning gestures excluding class {}".format(oneshot_class)) save_param_patch = "{}convnet_params/param-excl-class-{}".format(base_dir_path,oneshot_class) convnet.load_param_values(save_param_patch) try: fo1 = open("{}output_19cl/excl-class-{}.csv".format(base_dir_path,oneshot_class),"w") fo1.write("training_loss;validation_loss;validation_accuracy;epoch_time\n") except IOError as e: print("I/O error({0}): {1}".format(e.errno, e.strerror)) except: print("Unexpected error")