def consume_file_path( number: int, number_1a_path: str, number_1b_file: str, number_1c_file_path: str, number_1d_path_file: str, number_2a_path: InputPath(str), number_2b_file: InputPath(str), number_2c_file_path: InputPath(str), number_2d_path_file: InputPath(str), number_3a_path: InputTextFile(str), number_3b_file: InputTextFile(str), number_3c_file_path: InputTextFile(str), number_3d_path_file: InputTextFile(str), number_4a_path: InputBinaryFile(str), number_4b_file: InputBinaryFile(str), number_4c_file_path: InputBinaryFile(str), number_4d_path_file: InputBinaryFile(str), output_number_2a_path: OutputPath(str), output_number_2b_file: OutputPath(str), output_number_2c_file_path: OutputPath(str), output_number_2d_path_file: OutputPath(str), output_number_3a_path: OutputTextFile(str), output_number_3b_file: OutputTextFile(str), output_number_3c_file_path: OutputTextFile(str), output_number_3d_path_file: OutputTextFile(str), output_number_4a_path: OutputBinaryFile(str), output_number_4b_file: OutputBinaryFile(str), output_number_4c_file_path: OutputBinaryFile(str), output_number_4d_path_file: OutputBinaryFile(str), ): pass
def write_to_file_path( file_input1_path: InputPath(str), file_input2_file: InputTextFile(str), file_output1_path: OutputPath(str), file_output2_file: OutputTextFile(str), value_input1: str = 'foo', value_input2: str = 'foo', ) -> NamedTuple('Outputs', [ ('return_output1', str), ('return_output2', str), ]): with open(file_input1_path, 'r') as file_input1_file: with open(file_output1_path, 'w') as file_output1_file: file_output1_file.write(file_input1_file.read()) file_output2_file.write(file_input2_file.read()) return (value_input1, value_input2)
def write_to_file_path(number_file: OutputTextFile(int)): number_file.write(str(42))
def test_task( model_file: InputBinaryFile(str), examples_file: InputBinaryFile(str), confusion_matrix: OutputTextFile(str), results: OutputTextFile(str), ): """Connects to served model and tests example MNIST images.""" import time import json import numpy as np import requests from tensorflow.python.keras.backend import get_session from tensorflow.python.keras.saving import load_model from tensorflow.python.saved_model.simple_save import simple_save with get_session() as sess: model = load_model(model_file) simple_save( sess, '/output/mnist/1/', inputs={'input_image': model.input}, outputs={t.name: t for t in model.outputs}, ) model_url = 'http://localhost:9001/v1/models/mnist' for _ in range(60): try: requests.get(f'{model_url}/versions/1').raise_for_status() break except requests.RequestException: time.sleep(5) else: raise Exception("Waited too long for sidecar to come up!") response = requests.get(f'{model_url}/metadata') response.raise_for_status() assert response.json() == { 'model_spec': { 'name': 'mnist', 'signature_name': '', 'version': '1' }, 'metadata': { 'signature_def': { 'signature_def': { 'serving_default': { 'inputs': { 'input_image': { 'dtype': 'DT_FLOAT', 'tensor_shape': { 'dim': [ { 'size': '-1', 'name': '' }, { 'size': '28', 'name': '' }, { 'size': '28', 'name': '' }, { 'size': '1', 'name': '' }, ], 'unknown_rank': False, }, 'name': 'conv2d_input:0', } }, 'outputs': { 'dense_1/Softmax:0': { 'dtype': 'DT_FLOAT', 'tensor_shape': { 'dim': [{ 'size': '-1', 'name': '' }, { 'size': '10', 'name': '' }], 'unknown_rank': False, }, 'name': 'dense_1/Softmax:0', } }, 'method_name': 'tensorflow/serving/predict', } } } }, } examples = np.load(examples_file) assert examples['val_x'].shape == (100, 28, 28, 1) assert examples['val_y'].shape == (100, 10) response = requests.post(f'{model_url}:predict', json={'instances': examples['val_x'].tolist()}) response.raise_for_status() predicted = np.argmax(response.json()['predictions'], axis=1).tolist() actual = np.argmax(examples['val_y'], axis=1).tolist() zipped = list(zip(predicted, actual)) accuracy = sum(1 for (p, a) in zipped if p == a) / len(predicted) print(f"Accuracy: {accuracy:0.2f}")