def test_resnet(): # Load the model model_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'resnet18_v1') device = 'cpu' model = DLRModel(model_path, device) # Run the model image = np.load(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'dog.npy')).astype(np.float32) #flatten within a input array input_data = {'data': image} print('Testing inference on resnet18...') probabilities = model.run(input_data) #need to be a list of input arrays matching input names assert probabilities[0].argmax() == 151 assert model.get_input_names() == ["data"] assert model.get_input_dtypes() == ["float32"] assert model.get_output_dtypes() == ["float32"] assert model.get_input_dtype(0) == "float32" assert model.get_output_dtype(0) == "float32"
def test_mobilenet_v1_0_75_224_quant(): # Load the model model_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'mobilenet_v1_0.75_224_quant') device = 'cpu' model = DLRModel(model_path, device) # load image (dtype: uint8) image = np.load( os.path.join(os.path.dirname(os.path.abspath(__file__)), 'cat_224_uint8.npy')) print('Testing inference on mobilenet_v1_0.75_224_quant...') probabilities = model.run({'input': image}) assert probabilities[0].argmax() == 282 assert model.get_input_names() == ["input"] assert model.get_input_dtypes() == ["uint8"] assert model.get_output_dtypes() == ["uint8"] assert model.get_input_dtype(0) == "uint8" assert model.get_output_dtype(0) == "uint8" input2 = model.get_input("input") assert input2.dtype == 'uint8' assert input2.shape == (1, 224, 224, 3) assert (input2 == image).all()