Используйте saved_model.pb из Google Cloud automl для локального прогнозирования в Python

Я обучил модель с помощью Google Cloud Vision и скачал saved_mode.pb файл.

Вместо использования Руководства по контейнерам Google Cloud AutoML для начала контейнер докеров, я заинтересован в обнаружении объектов в моем собственном коде Python без какой-либо докерной машины. Подпись:

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"])))

person ying.di    schedule 23.04.2020    source источник
comment
Собственно, это устранило проблему. stackoverflow .com / questions / 58461211 /   -  person Di Ying    schedule 23.04.2020
comment
Отвечает ли это на ваш вопрос? сохраненная_модель из AutoML Vision Edge не загружается должным образом   -  person MyNameIsCaleb    schedule 29.04.2020