繁体   English   中英

如何使用 tensorflowjs_converter 转换 TensorFlow graph .pb 文件?

[英]How can I convert a TensorFlow graph .pb file using tensorflowjs_converter?

当我尝试使用 tensorflowjs_converter 转换我的冻结模型时,我收到此错误:

macbook-pro-6:tesla james$ tensorflowjs_converter --input_format=tf_frozen_model --output_node_names='MobilenetV1/Predictions/Reshape_1' --saved_model_tags=serve /retrained_graph.pb /web_model

(示例取自他们的 github: https : //github.com/tensorflow/tfjs-converter

这是我回来的错误:

Using TensorFlow backend.
Traceback (most recent call last):
  File "/Users/james/anaconda/bin/tensorflowjs_converter", line 7, in <module>
    from tensorflowjs.converters.converter import main
  File "/Users/james/anaconda/lib/python2.7/site-packages/tensorflowjs/__init__.py", line 21, in <module>
    from tensorflowjs import converters
  File "/Users/james/anaconda/lib/python2.7/site-packages/tensorflowjs/converters/__init__.py", line 22, in <module>
    from tensorflowjs.converters.keras_tfjs_loader import deserialize_keras_model
  File "/Users/james/anaconda/lib/python2.7/site-packages/tensorflowjs/converters/keras_tfjs_loader.py", line 25, in <module>
    import keras
  File "/Users/james/anaconda/lib/python2.7/site-packages/keras/__init__.py", line 3, in <module>
    from . import utils
  File "/Users/james/anaconda/lib/python2.7/site-packages/keras/utils/__init__.py", line 6, in <module>
    from . import conv_utils
  File "/Users/james/anaconda/lib/python2.7/site-packages/keras/utils/conv_utils.py", line 9, in <module>
    from .. import backend as K
  File "/Users/james/anaconda/lib/python2.7/site-packages/keras/backend/__init__.py", line 89, in <module>
    from .tensorflow_backend import *
  File "/Users/james/anaconda/lib/python2.7/site-packages/keras/backend/tensorflow_backend.py", line 5, in <module>
    import tensorflow as tf
  File "/Users/james/anaconda/lib/python2.7/site-packages/tensorflow/__init__.py", line 22, in <module>
    from tensorflow.python import pywrap_tensorflow  # pylint: disable=unused-import
  File "/Users/james/anaconda/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 52, in <module>
    from tensorflow.core.framework.graph_pb2 import *
  File "/Users/james/anaconda/lib/python2.7/site-packages/tensorflow/core/framework/graph_pb2.py", line 15, in <module>
    from tensorflow.core.framework import node_def_pb2 as tensorflow_dot_core_dot_framework_dot_node__def__pb2
  File "/Users/james/anaconda/lib/python2.7/site-packages/tensorflow/core/framework/node_def_pb2.py", line 15, in <module>
    from tensorflow.core.framework import attr_value_pb2 as tensorflow_dot_core_dot_framework_dot_attr__value__pb2
  File "/Users/james/anaconda/lib/python2.7/site-packages/tensorflow/core/framework/attr_value_pb2.py", line 15, in <module>
    from tensorflow.core.framework import tensor_pb2 as tensorflow_dot_core_dot_framework_dot_tensor__pb2
  File "/Users/james/anaconda/lib/python2.7/site-packages/tensorflow/core/framework/tensor_pb2.py", line 15, in <module>
    from tensorflow.core.framework import resource_handle_pb2 as tensorflow_dot_core_dot_framework_dot_resource__handle__pb2
  File "/Users/james/anaconda/lib/python2.7/site-packages/tensorflow/core/framework/resource_handle_pb2.py", line 22, in <module>
    serialized_pb=_b('\n/tensorflow/core/framework/resource_handle.proto\x12\ntensorflow\"r\n\x13ResourceHandleProto\x12\x0e\n\x06\x64\x65vice\x18\x01 \x01(\t\x12\x11\n\tcontainer\x18\x02 \x01(\t\x12\x0c\n\x04name\x18\x03 \x01(\t\x12\x11\n\thash_code\x18\x04 \x01(\x04\x12\x17\n\x0fmaybe_type_name\x18\x05 \x01(\tBn\n\x18org.tensorflow.frameworkB\x0eResourceHandleP\x01Z=github.com/tensorflow/tensorflow/tensorflow/go/core/framework\xf8\x01\x01\x62\x06proto3')
TypeError: __new__() got an unexpected keyword argument 'serialized_options'

我创建这个 .pb 文件的方式是将 tensorflow 用于诗人图像分类器。 它在 Python 中运行良好(我可以训练和创建 .pb 文件,甚至可以根据图像进行预测。我想将其转换为使用 nodejs 和 tensorflowjs,但我似乎无法将 .pb 文件转换为 tensorflowjs 所需的格式.

我决定搞砸并删除参数,如果我只使用这个命令:tensorflowjs_converter --help 它会抛出与上面相同的错误,wth?

请尝试以下代码。

pip install -U protobuf

通过更新 protobuf,您将能够解决上述问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM