def test_network(FLAGS): (x_train, y_train, x_test, y_test) = load_mnist_data(FLAGS.start_batch, FLAGS.batch_size) # Load saved model tf.import_graph_def(load_pb_file(FLAGS.model_file)) print("loaded model") print_nodes() # Get input / output tensors x_input = tf.compat.v1.get_default_graph().get_tensor_by_name( FLAGS.input_node) y_output = tf.compat.v1.get_default_graph().get_tensor_by_name( FLAGS.output_node) # Create configuration to encrypt input FLAGS, unparsed = server_argument_parser().parse_known_args() config = server_config_from_flags(FLAGS, x_input.name) with tf.compat.v1.Session(config=config) as sess: sess.run(tf.compat.v1.global_variables_initializer()) start_time = time.time() y_hat = y_output.eval(feed_dict={x_input: x_test}) elasped_time = time.time() - start_time print("total time(s)", np.round(elasped_time, 3)) if not FLAGS.enable_client: y_test_label = np.argmax(y_test, 1) if FLAGS.batch_size < 60: print("y_hat", np.round(y_hat, 2)) y_pred = np.argmax(y_hat, 1) correct_prediction = np.equal(y_pred, y_test_label) error_count = np.size(correct_prediction) - np.sum(correct_prediction) test_accuracy = np.mean(correct_prediction) print("Error count", error_count, "of", FLAGS.batch_size, "elements.") print("Accuracy: %g " % test_accuracy)
'./gc-emp-test/bin/argmax_1', '1', '12345', f'{out_server_name}{FLAGS.port}.txt', f'{out_final_name}{FLAGS.port}.txt' ]) # time.sleep(15) process.wait() argmax_time_end = time.time() with open(argmax_times_name, 'a') as outfile: outfile.write(str(argmax_time_end - argmax_time_start)) outfile.write("\n") log_timing(stage='server_client:finished 2PC', log_file=FLAGS.log_timing_file) if __name__ == "__main__": FLAGS, unparsed = server_argument_parser().parse_known_args() if unparsed: print("Unparsed flags:", unparsed) exit(1) if FLAGS.encrypt_server_data and FLAGS.enable_client: raise Exception( "encrypt_server_data flag only valid when client is not enabled. Note: the client can specify whether or not to encrypt the data using 'encrypt' or 'plain' in the configuration map" ) if FLAGS.model_file == "": raise Exception("FLAGS.model_file must be set") if not FLAGS.from_pytorch: # (x_train, y_train), (x_test, y_test) = client_data.get_dataset( # FLAGS.dataset) raise ValueError('must be from pytroch') else:
x_test = x_test[:FLAGS.batch_size] y_test = y_test[:FLAGS.batch_size] start_time = time.time() y_conv_val = y_conv.eval(feed_dict={x: x_test, y_: y_test}) elasped_time = (time.time() - start_time) print("total time(s)", np.round(elasped_time, 3)) print('y_conv_val', np.round(y_conv_val, 2)) y_test_batch = y_test[:FLAGS.batch_size] y_label_batch = np.argmax(y_test_batch, 1) correct_prediction = np.equal(np.argmax(y_conv_val, 1), y_label_batch) error_count = np.size(correct_prediction) - np.sum(correct_prediction) test_accuracy = np.mean(correct_prediction) print('Using average of 4 partitions_repeated sampling') print('Error count:', error_count, 'of', FLAGS.batch_size, 'elements.') print('Accuracy: ', test_accuracy) if __name__ == '__main__': parser = server_argument_parser() FLAGS, unparsed = parser.parse_known_args() if unparsed: print('Unparsed flags:', unparsed) if FLAGS.encrypt_server_data and FLAGS.enable_client: raise Exception( "encrypt_server_data flag only valid when client is not enabled. Note: the client can specify whether or not to encrypt the data using 'encrypt' or 'plain' in the configuration map" ) test_mnist_cnn(FLAGS)