Load a tensorflow "SavedModel" in dl4j

How can I load a tensorflow “SavedModel” in DL4J?

Deeplearning4j supports importing Keras models.

SameDiff, our automatic differentiation library that is built on top of ND4J, supports importing of frozen TensorFlow models only at present. SavedModel support may be added in the future.

You can convert models (including SavedModel) to frozen model format using the following tool:
https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/tools/freeze_graph.py

For example:

freeze_graph.freeze_graph(
    input_graph=path_to_your_graph,
    input_checkpoint=path_to_your_checkpoint,
    input_saver="",
    output_graph=output_graph,
    input_binary=True,
    output_node_names="loss/Softmax", 
    restore_op_name="save/restore_all",
    filename_tensor_name="save/Const:0",
    clear_devices=True,
    initializer_nodes="")

After conversion, you can load them in SameDiff using the SameDiff.importFrozenTF(File) method.

1 Like