def test_ssd_mobilenet_v2_model(): model = DLRModel(MODEL_PATH.as_posix()) data = np.load(DATA_PATH) assert model.get_input_names() == ['image_tensor'] assert model.get_output_names() == [ 'detection_scores:0', 'detection_classes:0', 'num_detections:0' ] assert model.get_input_dtypes() == ['uint8'] assert model.get_output_dtypes() == ['float32', 'float32', 'float32'] outputs = model.run({"image_tensor": data}) assert outputs[0].shape == (1, 100, 4) assert outputs[1].shape == (1, 100) assert outputs[2].shape == (1, 100) detections = np.multiply(np.ceil(outputs[1]), outputs[2]) expected = np.zeros(detections.shape) expected[:, :6] = np.array([[1., 1., 1., 2., 3., 1]]) comparison = detections == expected assert comparison.all()
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_ssd_mobilenet_v2_model(): model = DLRModel(MODEL_PATH.as_posix()) data = np.load(DATA_PATH) assert model.get_input_names() == ['image_tensor'] assert model.get_output_names() == [ 'detection_classes:0', 'num_detections:0', 'detection_boxes:0', 'detection_scores:0' ] assert model.get_input_dtypes() == ['uint8'] assert model.get_output_dtypes() == [ 'float32', 'float32', 'float32', 'float32' ] outputs = model.run({"image_tensor": data}) assert outputs[0].shape == (1, 100) assert outputs[1].shape == (1, ) assert outputs[2].shape == (1, 100, 4) assert outputs[3].shape == (1, 100) detections = np.multiply(np.ceil(outputs[3]), outputs[0]) expected = np.zeros(detections.shape) assert np.count_nonzero(detections) == outputs[1][0]
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()