tfjs icon indicating copy to clipboard operation
tfjs copied to clipboard

Use JSON instead of protocol buffers in the TensorFlow saved model converter.

Open nsthorat opened this issue 8 years ago • 5 comments

There are many situations we want to simply inspect the model topology to debug an issue, however the protocol buffer makes it extremely hard. The protocol buffer also makes us depend on protobufjs, which is a dependency which we should be able to remove.

It would be great to convert the model definition over to JSON (even simply with a toJSON() call on the proto during conversion). We can use a typescript interface for the JSON object on the other side.

This will also give us parity between the Keras / TensorFlow SavedModel worlds.

nsthorat avatar Nov 07 '18 15:11 nsthorat

I am having problems with .pb model while inspecting it.

  • I used tfjs-converter to convert the keras frozen graph to javascript format.
  • Loaded the model and weights manifest using tf.loadFrozenModel().
  • However I am facing difficulties while inspecting it.

Now I need to convert .pb to json and then use the model further? How does toJSON() call work?

Raza25 avatar Nov 14 '18 04:11 Raza25

cc @pyu10055 for advice on how to inspect the model topology proto.

nsthorat avatar Nov 15 '18 09:11 nsthorat

@pyu10055 could you assist in converting .pb to json. If not, is there any help available regarding using loaded .pb model in tensorflowjs and its inspection.

Raza25 avatar Nov 17 '18 10:11 Raza25

@Raza25 The model returns from loadFrozenModel() call contains an attribute graph of type GraphExecutor, which has a graph attribution that contains all the nodes of the graph. The kera layer information is lost when saving Keras to graph, but the node name can give you some hints on which variable scope the nodes belong to.

basically

const model = tf.loadFrozenModel(...); console.log(model.executor.graph.nodes);

pyu10055 avatar Nov 27 '18 21:11 pyu10055

Reopening this issue to track actually deleting all the protocol buffer code and removing the dependency before 1.0.

nsthorat avatar Feb 06 '19 21:02 nsthorat