无法使用tensorflowjs_converter

时间:2019-05-25 12:30:11

标签: python tensorflow keras tensorflow.js tensorflowjs-converter

我正在尝试第一次使用tensorflowjs以及响应来构建Web应用程序,我已经使用keras训练了模型,并将权重保存为hdf5文件格式,并且在此引用此链接-{{3} }

$ tensorflowjs_converter --input_format=keras /tmp/model.h5 /tmp/tfjs_model

这是我尝试的^,但随后出现错误。

  1. 最初在这里给出此错误(https://www.tensorflow.org/js/guide/conversion),我通过安装其他版本的tensorflowjs v0.6.4

  2. 解决了该错误
  3. 现在我已经安装了tensorflowjs v0.6.4,我得到了下面描述的另一个错误:

gaganganapathyas:~ codhek$ tensorflowjs_converter --input_format=keras /tmp/model.h5 /tmp/tfjs_model
Using TensorFlow backend.
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/2.7/bin/tensorflowjs_converter", line 6, in <module>
    from tensorflowjs.converters.converter import main
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tensorflowjs/__init__.py", line 21, in <module>
    from tensorflowjs import converters
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tensorflowjs/converters/__init__.py", line 24, in <module>
    from tensorflowjs.converters.tf_saved_model_conversion import convert_tf_saved_model
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tensorflowjs/converters/tf_saved_model_conversion.py", line 34, in <module>
    import tensorflow_hub as hub
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tensorflow_hub/__init__.py", line 25, in <module>
    from tensorflow_hub.feature_column import image_embedding_column
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tensorflow_hub/feature_column.py", line 25, in <module>
    from tensorflow_hub import module
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tensorflow_hub/module.py", line 23, in <module>
    from tensorflow_hub import native_module
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tensorflow_hub/native_module.py", line 26, in <module>
    from tensorflow_hub import compressed_module_resolver
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tensorflow_hub/compressed_module_resolver.py", line 35, in <module>
    from tensorflow_hub import resolver
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tensorflow_hub/resolver.py", line 34, in <module>
    FLAGS = tf.flags.FLAGS
AttributeError: 'module' object has no attribute 'flags'

甚至尝试将绝对路径与上述命令一起添加,但无效:

/Library/Frameworks/Python.framework/Versions/2.7/bin/tensorflowjs_converter --input_format=keras /tmp/weights.model /tmp/tfjs_model

这是我的keras cnn模型的链接:no add_to_collection was found when using tensorflowjs_converter

model.save_weights()model.save()有什么区别吗?

此外,如果我保存了模型的.json版,是否可以直接将其加载到我的js应用程序中?

1 个答案:

答案 0 :(得分:0)

在您将tensorflow v0.6.4keras v2.1.6一起使用时,它就可以工作,尽管安装keras可能会警告您

ERROR: tensorflowjs 0.6.4 has requirement keras==2.2.2, but you'll have keras 2.1.6 which is incompatible.

这是因为tensorflow v0.6.4需要keras==2.2.2,但是keras-preprocessing版本不匹配!