To use TensorFlow.js, the model must first be converted to the correct format using tfjs-converter. It can convert Keras models, frozen models, and SavedModels. Installation instructions are provided in the GitHub repository.
Then, converting a model is very similar to the process done for TensorFlow Lite. Instead of being done in Python, it is done from the command line:
$ tensorflowjs_converter ./saved_model --input_format=tf_saved_model my-tfjs --output_format tfjs_graph_model
Similar to TensorFlow Lite, we need to specify the names of the output nodes.
The output is composed of multiple files:
- optimized_model.pb: Contains the model graph
- weights_manifest.json: Contains information about the list of weights
- group1-shard1of5, group1-shard2of5, ..., group1-shard5of5: Contains the weights of the model split into multiple files
The model is split into multiple files because parallel downloads are usually faster.