我第一次尝试使用 tensorflowjs 和 react 来构建一个 web 应用程序,我已经使用 keras 训练了我的模型并将我的权重保存为 hdf5 文件格式,我在这里指的是这个链接 - https://www.tensorflow .org/js/guide/conversion
$ tensorflowjs_converter --input_format=keras /tmp/model.h5 /tmp/tfjs_model
这个 ^ 是我尝试过的,但后来我遇到了错误。
最初在这里给出了这个错误(使用 tensorflowjs_converter 时没有找到 add_to_collection)我通过安装不同版本的 tensorflowjs v0.6.4 来解决它
现在我已经安装了 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 模型的链接:https ://www.kaggle.com/codhek/cnn-using-keras-using-csv-accuracy-99-82
model.save_weights()
和model.save()
有什么区别吗?
另外,如果我保存.json
模型的一个版本,我可以直接将它加载到我的 js 应用程序中吗?