def test_json_serializer_csv_buffer():
    csv_file_path = os.path.join(DATA_DIR, "with_integers.csv")
    with open(csv_file_path) as csv_file:
        validation_value = csv_file.read()
        csv_file.seek(0)
        result = json_serializer(csv_file)
        assert result == validation_value
def test_json_serializer_csv_buffer():
    csv_file_path = os.path.join(DATA_DIR, "with_integers.csv")
    with open(csv_file_path) as csv_file:
        validation_value = csv_file.read()
        csv_file.seek(0)
        result = json_serializer(csv_file)
        assert result == validation_value
Esempio n. 3
0
 def __call__(self, data):
     """
     Args:
         data:
     """
     if isinstance(data, tensor_pb2.TensorProto):
         return json_format.MessageToJson(data)
     return json_serializer(data)
Esempio n. 4
0
    def __call__(self, data):
        """
        Args:
            data:
        """

        from tensorflow.core.framework import tensor_pb2  # pylint: disable=no-name-in-module

        if isinstance(data, tensor_pb2.TensorProto):
            return json_format.MessageToJson(data)
        return json_serializer(data)
def test_json_serializer_python_array():
    result = json_serializer([1, 2, 3])

    assert result == '[1, 2, 3]'
def test_json_serializer_numpy_invalid_empty():
    with pytest.raises(ValueError) as invalid_input:
        json_serializer(np.array([]))

    assert "empty array" in str(invalid_input)
def test_json_serializer_numpy_valid_2dimensional():
    result = json_serializer(np.array([[1, 2, 3], [3, 4, 5]]))

    assert result == '[[1, 2, 3], [3, 4, 5]]'
def test_json_serializer_numpy_valid():
    result = json_serializer(np.array([1, 2, 3]))

    assert result == '[1, 2, 3]'
Esempio n. 9
0
def test_json_serializer_python_dictionary_invalid_empty():
    assert json_serializer({}) == "{}"
def test_json_serializer_python_array():
    result = json_serializer([1, 2, 3])

    assert result == '[1, 2, 3]'
def test_json_serializer_python_dictionary_invalid_empty():
    with pytest.raises(ValueError) as error:
        json_serializer({})
    assert "empty dictionary" in str(error)
def test_json_serializer_numpy_valid_2dimensional():
    result = json_serializer(np.array([[1, 2, 3], [3, 4, 5]]))

    assert result == '[[1, 2, 3], [3, 4, 5]]'
Esempio n. 13
0
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True, help="path of the image")
args = vars(ap.parse_args())

image_path = args['image']


# define function to read and transform image
def transform_image(image_path):
    img = image.img_to_array(image.load_img(image_path,
                                            target_size=(250, 250))) / 255
    img = np.expand_dims(img, axis=0)
    return img


data = {'instances': transform_image(image_path)}
payload = json_serializer(data)

# sending post request and saving response as response object
response = sage.invoke_endpoint(EndpointName=MODEL_ENDPOINT,
                                ContentType='application/json',
                                Body=payload)

r = response.get('Body').read()
r = json.loads(r)

prob = r['predictions'][0][0]
cat = "Chart" if prob > .5 else "Meme"

# extracting the response
print({"probability": prob, "class": cat})
def test_json_serializer_python_dictionary_invalid_empty():
    with pytest.raises(ValueError) as error:
        json_serializer({})
    assert "empty dictionary" in str(error)
def test_json_serializer_python_invalid_empty():
    with pytest.raises(ValueError) as error:
        json_serializer([])
    assert "empty array" in str(error)
def test_json_serializer_python_dictionary():
    d = {"gender": "m", "age": 22, "city": "Paris"}

    result = json_serializer(d)

    assert json.loads(result) == d
def test_json_serializer_python_dictionary():
    d = {"gender": "m", "age": 22, "city": "Paris"}

    result = json_serializer(d)

    assert json.loads(result) == d
def test_json_serializer_numpy_valid():
    result = json_serializer(np.array([1, 2, 3]))

    assert result == '[1, 2, 3]'
def test_json_serializer_python_invalid_empty():
    with pytest.raises(ValueError) as error:
        json_serializer([])
    assert "empty array" in str(error)
Esempio n. 20
0
def test_json_serializer_python_invalid_empty():
    assert json_serializer([]) == "[]"
Esempio n. 21
0
def test_json_serializer_empty():
    assert json_serializer(np.array([])) == "[]"
def test_json_serializer_numpy_invalid_empty():
    with pytest.raises(ValueError) as invalid_input:
        json_serializer(np.array([]))

    assert "empty array" in str(invalid_input)