Convert output of retrain.py to tensorflow.js

匆匆过客 提交于 2019-12-12 16:05:49

问题


The script retrain.py described in How to Retrain an Image Classifier for New Categories was run as

python retrain.py --tfhub_module https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/feature_vector/2 --image_dir /tmp/test

and produced the output file /tmp/output_graph.pb. Converting this with

tensorflowjs_converter --input_format=tf_saved_model --output_format=tfjs_graph_model /tmp/output_graph.pb /tmp/model

failed with

IOError: SavedModel file does not exist at: /tmp/output_graph.pb/{saved_model.pbtxt|saved_model.pb}

If the file output_graph.pb is renamed to saved_model.pb (by @edkeveked), the error changes to

RuntimeError: MetaGraphDef associated with tags 'serve' could not be found in SavedModel. To inspect available tag-sets in the SavedModel, please use the SavedModel CLI: saved_model_cli

saved_model_cli show --dir . reports an empty tag set.

How can this be fixed?


回答1:


The input path is the path of the folder and not of the file. Consider the following:

tensorflowjs_converter --input_format=tf_saved_model --output_format=tfjs_graph_model /tmp /tmp/model



回答2:


As hinted by @Ping Yu in Retrain image detection with MobileNet, you can use

python retrain.py --tfhub_module https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/feature_vector/2 \
    --image_dir /tmp/flower_photos --saved_model_dir /tmp/saved_retrained_model
tensorflowjs_converter --input_format=tf_saved_model \
    --output_format=tfjs_graph_model \
    --saved_model_tags=serve \
    /tmp/saved_retrained_model/ /tmp/converted_model/

This saves the model using the saved model format.



来源:https://stackoverflow.com/questions/55829593/convert-output-of-retrain-py-to-tensorflow-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!