Я пытаюсь запустить модель тензорного потока на устройстве SBC на основе руки, близком к raspberryPi 3b +.Я скомпилировал библиотеку tenorflow из исходного кода, ориентированного на архитектуру armv7l, используя этот репозиторий https://github.com/lhelontra/tensorflow-on-arm
, сохраняющий флаг поддержки GoogleCloud (GC) во время сборки.Я все еще получаю сообщение об ошибке:
File "/home/pi/tensorflow_pi_test/predict_image_v6.py", line 165, in <module>
result = predict_image_tflite('./1.jpg', './denseNet201_model_final.pb')
File "/home/pi/tensorflow_pi_test/predict_image_v6.py", line 143, in predict_image_tflite
interpreter = tf.contrib.lite.Interpreter(model_path="converted_model.tflite")
File "/home/pi/venv_tf_1.10/lib/python3.5/site-packages/tensorflow/python/util/lazy_loader.py", line 53, in __getattr__
module = self._load()
File "/home/pi/venv_tf_1.10/lib/python3.5/site-packages/tensorflow/python/util/lazy_loader.py", line 42, in _load
module = importlib.import_module(self.__name__)
File "/home/pi/venv_tf_1.10/lib/python3.5/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 673, in exec_module
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "/home/pi/venv_tf_1.10/lib/python3.5/site-packages/tensorflow/contrib/__init__.py", line 38, in <module>
from tensorflow.contrib import cloud
ImportError: cannot import name 'cloud'
Process finished with exit code 1
Код, который я использую для выполнения модели на платформе arm:
def predict_image_tflite(image_path, model_path):
short_edge_min = 256
short_edge_max = 384
center_crop_size = (224, 224)
# open image
img = Image.open(image_path)
# show image
# plt.imshow(img)
# downsample image
width, height = img.size
tmp = min(width, height)
short_edge_resize = np.random.randint(short_edge_min, short_edge_max)
# check python version
py_ver = platform.python_version()
if py_ver.split('.')[0] == '3':
# python 3
width = int(width * short_edge_resize / tmp)
height = int(height * short_edge_resize / tmp)
elif py_ver.split('.')[0] == '2':
# python 2
width = width * short_edge_resize / tmp
height = height * short_edge_resize / tmp
img = img.resize((width, height))
img = np.array(img)
# center crop image
centerw, centerh = img.shape[1] // 2, img.shape[0] // 2
halfw, halfh = center_crop_size[1] // 2, center_crop_size[0] // 2
offsetw, offseth = 0, 0
if center_crop_size[0] % 2 == 1:
offseth = 1
if center_crop_size[1] % 2 == 1:
offsetw = 1
img = img[centerh - halfh:centerh + halfh + offseth, centerw - halfw:centerw + halfw + offsetw, :]
# expand image dimension to 4D
img = np.expand_dims(img, axis=0)
## Now the prediction script runs
# Load TFLite model and allocate tensors.
interpreter = tf.contrib.lite.Interpreter(model_path="converted_model.tflite")
interpreter.allocate_tensors()
# Get input and output tensors.
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()
#Testing out model on random test data
input_shape = input_details[0]['shape']
input_data = np.array(np.random.random_sample(input_shape), dtype=np.float32)
interpreter.set_tensor(input_details[0]['index'], input_data)
interpreter.invoke()
output_data = interpreter.get_tensor(output_details[0]['index'])
print(input_data)
print(output_data)
Есть предложения о том, как подойти к этому блокировщику?