7
votes

I'm porting body-pix to Python and C++ and want to export the body-pix pre-trained model for tensorflow.js into a tensorflow frozen graph. Is it possible?

I've already download the following files and tried to convert using tensorflowjs_converter, but it didn't work.

The result is here.

$ tensorflowjs_converter --input_format tfjs_layers_model --output_format keras posenet_mobilenet_025_partmap/model.json test.h5

Traceback (most recent call last):
  File "/home/xxx/anaconda3/envs/tfjs_test2/bin/tensorflowjs_converter", line 10, in <module>
    sys.exit(main())
  File "/home/xxx/anaconda3/envs/tfjs_test2/lib/python3.6/site-packages/tensorflowjs/converters/converter.py", line 368, in main
    FLAGS.output_path)
  File "/home/xxx/anaconda3/envs/tfjs_test2/lib/python3.6/site-packages/tensorflowjs/converters/converter.py", line 169, in dispatch_tensorflowjs_to_keras_h5_conversion
    model = keras_tfjs_loader.load_keras_model(config_json_path)
  File "/home/xxx/anaconda3/envs/tfjs_test2/lib/python3.6/site-packages/tensorflowjs/converters/keras_tfjs_loader.py", line 218, in load_keras_model
    use_unique_name_scope=use_unique_name_scope)
  File "/home/xxx/anaconda3/envs/tfjs_test2/lib/python3.6/site-packages/tensorflowjs/converters/keras_tfjs_loader.py", line 65, in _deserialize_keras_model
    model = keras.models.model_from_json(json.dumps(model_topology_json))
  File "/home/xxx/anaconda3/envs/tfjs_test2/lib/python3.6/site-packages/tensorflow/python/keras/saving/model_config.py", line 96, in model_from_json
    return deserialize(config, custom_objects=custom_objects)
  File "/home/xxx/anaconda3/envs/tfjs_test2/lib/python3.6/site-packages/tensorflow/python/keras/layers/serialization.py", line 81, in deserialize
    layer_class_name = config['class_name']
KeyError: 'class_name'

The converter version is here.

tensorflowjs 1.0.1

Dependency versions:
  keras 2.2.4-tf
  tensorflow 2.0.0-dev20190405

On ubuntu 16.04 LTS and anaconda 3. I've tried tensorflowjs 0.8.5, but it also didn't work.

It will be helpful if you tell me how to convert them. Either keras format or tensorflow frozen graph is OK. I think that both can be converted to each other.

1
Please take a look at this related thread github.com/tensorflow/tfjs/issues/1280#issuecomment-466850320 and github.com/tensorflow/tfjs/issues/1280 for more context. This is a current limitation where TFJS graph model cannot be converted to TF SavedModel and BodyPix model is converted from TF SavedModel and not Keras.Tensorflow Support
@TensorflowSupport I could not find any information how to convet it to .pb or any oder format in order to used it on Python. Can you help me? The second version with the multi-person support is amazingAitul

1 Answers

7
votes
  • Download the model.json file

Eg: https://storage.googleapis.com/tfjs-models/savedmodel/bodypix/resnet50/float/model-stride16.json

  • Download Corresponding weights from manifest.json

https://storage.googleapis.com/tfjs-models/savedmodel/bodypix/resnet50/float/manifest.json

  • Install tfjs_graph_converter

from https://github.com/ajaichemmanam/tfjs-to-tf

  • Convert model to .pb file

tfjs_graph_converter path/to/js/model path/to/frozen/model.pb

Here is an example of POSENET converted to keras h5 model. https://github.com/tensorflow/tfjs/files/3943875/posenet.zip Same way you can use the bodypix models and convert it .