Я обучил модель с использованием облачного видения Google и загрузил файл saved_mode.pb
.
Вместо того, чтобы использовать Руководство по контейнерам Google Cloud AutoML для запуска контейнера docker, я заинтересован в обнаружении объектов в моем собственном python коде без какой-либо машины docker. Подпись:
inputs['image_bytes'] tensor_info:
dtype: DT_STRING
shape: (-1)
name: encoded_image_string_tensor:0
inputs['key'] tensor_info:
dtype: DT_STRING
shape: (-1)
name: key:0
, которая вызвала ошибку ниже: [Unable to decode bytes as JPEG, PNG, GIF, or BMP]
2020-04-22 22:11:41.785038: W tensorflow/core/common_runtime/base_collective_executor.cc:216] BaseCollectiveExecutor::StartAbort Invalid argument: assertion failed: [Unable to decode bytes as JPEG, PNG, GIF, or BMP]
[[{{node map/while/decode_image/cond_jpeg/cond_png/cond_gif/Assert_1/Assert}}]]
Traceback (most recent call last):
File "predict.py", line 29, in <module>
print(infer(image_bytes = tf.convert_to_tensor([str(image_bytes)]), key = tf.convert_to_tensor(["123"])))
File "C:\Users\DiYing\anaconda3\lib\site-packages\tensorflow_core\python\eager\function.py", line 1081, in __call__
return self._call_impl(args, kwargs)
File "C:\Users\DiYing\anaconda3\lib\site-packages\tensorflow_core\python\eager\function.py", line 1121, in _call_impl
return self._call_flat(args, self.captured_inputs, cancellation_manager)
File "C:\Users\DiYing\anaconda3\lib\site-packages\tensorflow_core\python\eager\function.py", line 1224, in _call_flat
ctx, args, cancellation_manager=cancellation_manager)
File "C:\Users\DiYing\anaconda3\lib\site-packages\tensorflow_core\python\eager\function.py", line 511, in call
ctx=ctx)
File "C:\Users\DiYing\anaconda3\lib\site-packages\tensorflow_core\python\eager\execute.py", line 67, in quick_execute
six.raise_from(core._status_to_exception(e.code, message), None)
File "<string>", line 3, in raise_from
Мой код ниже:
import tensorflow as tf
import io
import base64
export_path = '.'
loaded = tf.saved_model.load(".")
infer = loaded.signatures["serving_default"]
path = './57.png'
with io.open(path, 'rb') as image_file:
encoded_image = base64.b64encode(image_file.read()).decode('utf-8')
print(infer(image_bytes = tf.convert_to_tensor([str(encoded_image)]), key = tf.convert_to_tensor(["123"])))
Я также пытался использовать код ниже, без удачи.
with io.open(path, 'rb') as image_file:
encoded_image = base64.b64encode(image_file.read()).decode('utf-8')
image_bytes2 = {'b64': str(encoded_image)}
print(infer(image_bytes = tf.convert_to_tensor([str(image_bytes2)]), key = tf.convert_to_tensor(["123"])))