首页 > 解决方案 > tensorflow 无法将 dtype 资源的张量转换为 NumPy 数组。特飞特

问题描述

我已经训练了一个网络(下面的 git 链接)并以保存的模型格式保存。并想将其转换为 tflite。我正在为 tflite 转换器使用 python API(tflite.py在下面的 git 链接中)。但我不能这样做。

系统信息:
OS平台和发行版: Ubuntu 18.04.3 LTS
TensorFlow版本: tensorflow/tensorflow:2.2.0-gpu (docker)

网络链接并保存模型代码。

转换器调用的输出:

File "tflite.py", line 22, in convert_model
  tflite_model = converter.convert()
File "/usr/local/lib/python3.6/dist-packages/tensorflow/lite/python/lite.py", line 459, in convert
  self._funcs[0], lower_control_flow=False))
File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/convert_to_constants.py", line 706, in convert_variables_to_constants_v2_as_graph
  func, lower_control_flow, aggressive_inlining)
File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/convert_to_constants.py", line 457, in _convert_variables_to_constants_v2_impl
  tensor_data = _get_tensor_data(func)
File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/convert_to_constants.py", line 217, in _get_tensor_data
  data = val_tensor.numpy()
File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/ops.py", line 961, in numpy
  maybe_arr = self._numpy()  # pylint: disable=protected-access
File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/ops.py", line 929, in _numpy
  six.raise_from(core._status_to_exception(e.code, e.message), None)
File "<string>", line 3, in raise_from
tensorflow.python.framework.errors_impl.InvalidArgumentError: Cannot convert a Tensor of dtype resource to a NumPy array.

已保存模型的链接

标签: tensorflow

解决方案


推荐阅读