def package_simple_addition_model(self, do_fail=False): with TemporaryDirectory() as test_dir: neuropod_path = os.path.join(test_dir, "test_neuropod") model_code_dir = os.path.join(test_dir, "model_code") os.makedirs(model_code_dir) with open(os.path.join(model_code_dir, "addition_model.py"), "w") as f: f.write(ADDITION_MODEL_SOURCE) # `create_python_neuropod` runs inference with the test data immediately # after creating the neuropod. Raises a ValueError if the model output # does not match the expected output. create_python_neuropod( neuropod_path=neuropod_path, model_name="addition_model", data_paths=[], code_path_spec=[{ "python_root": model_code_dir, "dirs_to_package": [ "" # Package everything in the python_root ], }], entrypoint_package="addition_model", entrypoint="get_model", # Get the input/output spec along with test data **get_addition_model_spec(do_fail=do_fail)) # Run some additional checks check_addition_model(neuropod_path)
def package_simple_addition_model(self, do_fail=False): with TemporaryDirectory() as test_dir: neuropod_path = os.path.join(test_dir, "test_neuropod") model_code_dir = os.path.join(test_dir, "model_code") os.makedirs(model_code_dir) model_ops_dir = os.path.join(test_dir, "model_ops") os.makedirs(model_ops_dir) with open(os.path.join(model_code_dir, "model.prototxt"), "w") as f: f.write(ADDITION_MODEL_SOURCE) with open(os.path.join(model_ops_dir, "CustomLayer.py"), "w") as f: f.write(CUSTOM_OPS) create_caffe_neuropod( neuropod_path=neuropod_path, model_name="addition_model", prototxt=os.path.join(model_code_dir, "model.prototxt"), node_name_mapping={ 'x': 'data1', 'y': 'data2', 'out': 'out', }, code_path_spec=[{ "python_root": test_dir, "dirs_to_package": ["model_ops"], }], # Get the input/output spec along with test data **get_addition_model_spec(do_fail=do_fail)) # Run some additional checks check_addition_model(neuropod_path)
def package_simple_addition_model(self, do_fail=False): with TemporaryDirectory() as test_dir: neuropod_path = os.path.join(test_dir, "test_neuropod") create_onnx_neuropod( neuropod_path=neuropod_path, model_name="addition_model", onnx_model=create_onnx_addition_model(), node_name_mapping={ "x": "X", "y": "Y", "out": "Z", }, # Get the input/output spec along with test data **get_addition_model_spec(do_fail=do_fail)) # Run some additional checks check_addition_model(neuropod_path)
def package_simple_addition_model(self, do_fail=False, **kwargs): with TemporaryDirectory() as test_dir: neuropod_path = os.path.join(test_dir, "test_neuropod") # Get the input/output spec along with test data kwargs.update(get_addition_model_spec(do_fail=do_fail)) # `create_tensorflow_neuropod` runs inference with the test data immediately # after creating the neuropod. Raises a ValueError if the model output # does not match the expected output. create_tensorflow_neuropod( neuropod_path=neuropod_path, model_name="addition_model", trackable_obj=create_tf_addition_model(), **kwargs) # Run some additional checks check_addition_model(neuropod_path)
def package_simple_addition_model(self, do_fail=False): with TemporaryDirectory() as test_dir: neuropod_path = os.path.join(test_dir, "test_neuropod") net = AdditionModel() net.initialize() net.hybridize() net.forward(mx.nd.array([1, 2, 3]), mx.nd.array([1, 2, 3])) create_mxnet_neuropod( neuropod_path=neuropod_path, model_name="addition_model", module=net, input_names=['data0', 'data1'], # Get the input/output spec along with test data **get_addition_model_spec(do_fail=do_fail)) # Run some additional checks check_addition_model(neuropod_path)
def package_simple_addition_model(self, do_fail=False): for model in [ AdditionModel, AdditionModelDictInput, AdditionModelTensorOutput ]: with TemporaryDirectory() as test_dir: neuropod_path = os.path.join(test_dir, "test_neuropod") # `create_torchscript_neuropod` runs inference with the test data immediately # after creating the neuropod. Raises a ValueError if the model output # does not match the expected output. create_torchscript_neuropod( neuropod_path=neuropod_path, model_name="addition_model", module=model(), # Get the input/output spec along with test data **get_addition_model_spec(do_fail=do_fail)) # Run some additional checks check_addition_model(neuropod_path)
def package_simple_addition_model(self, alias_names=False, do_fail=False): with TemporaryDirectory() as test_dir: neuropod_path = os.path.join(test_dir, "test_neuropod") if alias_names: node_name_mapping = {"x": "x_", "y": "y_", "out": "out_"} else: node_name_mapping = None # `create_keras_neuropod` runs inference with the test data immediately # after creating the neuropod. Raises a ValueError if the model output # does not match the expected output. create_keras_neuropod( neuropod_path=neuropod_path, model_name="addition_model", sess=tf.keras.backend.get_session(), model=create_keras_addition_model(node_name_mapping), node_name_mapping=node_name_mapping, # Get the input/output spec along with test data **get_addition_model_spec(do_fail=do_fail)) # Run some additional checks check_addition_model(neuropod_path)
def package_simple_addition_model(self, do_fail=False, **kwargs): with TemporaryDirectory() as test_dir: neuropod_path = os.path.join(test_dir, "test_neuropod") # Get the input/output spec along with test data kwargs.update(get_addition_model_spec(do_fail=do_fail)) # `create_tensorflow_neuropod` runs inference with the test data immediately # after creating the neuropod. Raises a ValueError if the model output # does not match the expected output. create_tensorflow_neuropod( neuropod_path=neuropod_path, model_name="addition_model", graph_def=create_tf_addition_model(), node_name_mapping={ "x": "some_namespace/in_x:0", "y": "some_namespace/in_y:0", # The `:0` is optional "out": "some_namespace/out", }, **kwargs) # Run some additional checks check_addition_model(neuropod_path)
def package_simple_addition_model(self, do_fail=False): with TemporaryDirectory() as test_dir: neuropod_path = os.path.join(test_dir, "test_neuropod") INIT_NET = os.path.join(test_dir, "init_net.pb") PREDICT_NET = os.path.join(test_dir, "predict_net.pb") SaveNet(INIT_NET, PREDICT_NET, workspace, create_caffe2_addition_model()) create_caffe2_neuropod( neuropod_path=neuropod_path, model_name="addition_model", node_name_mapping={ "x": "X", "y": "Y", "out": "Z", }, predict_net=PREDICT_NET, init_net=INIT_NET, # Get the input/output spec along with test data **get_addition_model_spec(do_fail=do_fail)) # Run some additional checks check_addition_model(neuropod_path)