Skip to content

How to Freeze Graph in Tensorflow.Net #702

@quanap5

Description

@quanap5

Hello,
I am working to save the checkpoint file of the model to the Protocol Buffer file for deployment.
As I know, to archive it, we should follow the important steps:
1-Save checkpoints.
2-Save graph.
3-Freeze graph.

I take a look at the example of logistic regression here. I focused on this.

public void SaveModel(Session sess)
        {
            //save checkpoint of model using train.Saver.
            var saver = tf.train.Saver();
            var save_path = saver.save(sess, ".resources/logistic_regression/model.ckpt");
            print("Finish save checkpoint");
            //this will only save the graph but variables will not be saved.
            tf.train.write_graph(sess.graph, ".resources/logistic_regression", "model.pbtxt", as_text:true);
            print("Finish write graph");
            //this will freeze graph (graph + parametters)
            //Method 1:
            //FreezeGraph.freeze_graph(input_graph: ".resources/logistic_regression/model.pbtxt",
            //                  input_saver: "",
            //                  input_binary: false,
            //                  input_checkpoint: ".resources/logistic_regression/model.ckpt",
            //                  output_node_names: "Softmax",
            //                  restore_op_name: "save/restore_all",
            //                  filename_tensor_name: "save/Const:0",
            //                  output_graph: ".resources/logistic_regression/model.pb",
            //                  clear_devices: true,
            //                  initializer_nodes: "");
            //Method: 2
            tf.train.freeze_graph(".resources/logistic_regression/model.ckpt", ".resources/logistic_regression/test.pb", new string[] { "Softmax" });
            print("Finish freeze graph");
        }

I modified a bit by add tf.train.freeze_graph(..) as above. But 2 both methods output only checkpoint file, text graph WITHOUT .pb.
pb_output

Do you have any idea about my issue? How to save the model as .pb file using Tensorflow.Net?
Thank you very much.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions