Tensorflow prediciton error, invalidArgumentError: assertion failed: [Unable to decode bytes as JPEG, PNG, GIF, or BMP]

Lex Hoffman Responses • 2 Posted • Mar 16 2019
I trained a Tensorflow Ssd object-detection model using Google object-detection Api and i exported the trained model using the provided "export_inference_graph.py" script as "Saved_model.pb" file with "encoded_image_string_tensor" as input type, however when i tried to make prediction to the model,

i got the following error:
tensorflow.python.framework.errors_impl.InvalidArgumentError: assertion failed: [Unable to decode bytes as JPEG, PNG, GIF, or BMP]
İ loaded the model into a graph as follow:
with tf.Session() as sess:
tf.saved_model.loader.load(sess, [tf.saved_model.tag_constants.SERVING], saved_model_file)
graph = tf.get_default_graph()
And made the prediction as follow:
# Convert the image into base64 encoded string
img = Image.open(IMAGE_PATH) resized_img = img.resize((300, 300),
Image.ANTIALIAS) binary_io = io.BytesIO() resized_img.save(binary_io, "JPEG")
bytes_string_image = base64.b64encode(binary_io.getvalue()).decode("utf-8")

# Define the input and output placeholder tensors
input_tensor = graph.get_tensor_by_name('encoded_image_string_tensor:0')
tensor_dict = {}
for key in ['num_detections', 'detection_boxes', 'detection_scores', 'detection_classes']:
tensor_name = key + ':0' tensor_dict[key] = graph.get_tensor_by_name(tensor_name)

# Finally, do the prediction
output_dict = sess.run(tensor_dict, feed_dict={ input_tensor: bytes_string_image})

Write your response...