Я обучил модель обнаружения объектов Tensorflow Ssd с помощью API обнаружения объектов Google и экспортировал обученную модель, используя предоставленный сценарий "export_inference_graph.py", в качестве файла "Saved_model.pb" с "encoded_image_string_tensor" в качестве типа ввода, однако, когдаЯ попытался сделать прогноз для модели, я получил следующую ошибку:
tensorflow.python.framework.errors_impl.InvalidArgumentError: assertion failed: [Unable to decode bytes as JPEG, PNG, GIF, or BMP]
Я загрузил модель в график следующим образом:
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()
И сделал прогноз следующим образом:
# 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 prediciton
output_dict = sess.run(tensor_dict, feed_dict={
input_tensor: bytes_string_image})