4

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?

serv-inc
  • 35,772
  • 9
  • 166
  • 188
  • The error says it all. The file is not found – edkeveked Apr 24 '19 at 12:28
  • @edkeveked: the file `/tmp/output_graph.pb` exists along with `output_labels.txt`. Is this a different format? – serv-inc Apr 24 '19 at 12:44
  • 1
    Have you solved it? I ran into the same problem using the tfjs sample [mobilenet V2,](https://storage.googleapis.com/mobilenet_v2/checkpoints/mobilenet_v2_1.0_224.tgz) – 季谢尔 May 07 '19 at 12:17
  • @季谢尔: No. The alternative failed as well. Even a bounty on https://stackoverflow.com/questions/55849309/retrain-image-detection-with-mobilenet?noredirect=1&lq=1 yielded no result. See the issue at https://github.com/tensorflow/tensorflow/issues/28365 – serv-inc May 07 '19 at 20:39
  • @季谢尔: see [the answer](https://stackoverflow.com/a/56084489/1587329) – serv-inc May 11 '19 at 12:11

2 Answers2

2

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
edkeveked
  • 17,989
  • 10
  • 55
  • 93
  • After changing to the directory and renaming the `.pb` file, a different error occurs. See the edit. Still a step in the right direction. Thanks – serv-inc Apr 24 '19 at 13:02
  • Though I can't tell exactly why you're having the current error, I could suggest to add other flags `--output_node_names="final_result"`, `--saved_model_tags=serve` to tfjs-converter command. – edkeveked Apr 24 '19 at 14:03
  • both together yielded "*TensorFlow.js model converters.: error: unrecognized arguments: --output_node_names=final_result*", skipping that resulted in the same "*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`*" – serv-inc Apr 24 '19 at 14:35
1

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.

serv-inc
  • 35,772
  • 9
  • 166
  • 188