question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error loading a frozen graph ( float incompatible with float_ref )

See original GitHub issue

I froze the 20170131-234652 model using the freeze_graph.py, but I cannot load it in C++.

I first read the binaryproto successfully as:

tensorflow::GraphDef graph_def;
Status load_graph_status =  ReadBinaryProto(tensorflow::Env::Default(), graph_file_name, &graph_def);

But, it gives an error while creating the graph to be used for the session:

std::unique_ptr<tensorflow::Session> session(tensorflow::NewSession(tensorflow::SessionOptions()));
tensorflow::Status sessionCreateStatus = session->Create(graphDef);

The error is:

Invalid argument: Input 0 of node InceptionResnetV1/Block8/Branch_1/Conv2d_0c_3x1/BatchNorm/cond/AssignMovingAvg_1/Switch was passed float from InceptionResnetV1/Block8/Branch_1/Conv2d_0c_3x1/BatchNorm/moving_variance:0 incompatible with expected float_ref.

Any ideas how to solve this problem?

Thanks in advance 😃

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:26 (8 by maintainers)

github_iconTop GitHub Comments

28reactions
Lunrotcommented, Feb 21, 2017

my code

        saver = tf.train.import_meta_graph(os.path.join(os.path.expanduser(args.model_dir), 
            'model-' + os.path.basename(os.path.normpath(args.model_dir)) + '.meta'), clear_devices=True)
        tf.get_default_session().run(tf.global_variables_initializer())
        tf.get_default_session().run(tf.local_variables_initializer())
        saver.restore(sess, tf.train.latest_checkpoint(os.path.expanduser(args.model_dir)))
        
        output_node_names = 'embeddings'
        
        # for fixing the bug of batch norm
        gd = sess.graph.as_graph_def()
        for node in gd.node:            
            if node.op == 'RefSwitch':
                node.op = 'Switch'
                for index in xrange(len(node.input)):
                    if 'moving_' in node.input[index]:
                        node.input[index] = node.input[index] + '/read'
            elif node.op == 'AssignSub':
                node.op = 'Sub'
                if 'use_locking' in node.attr: del node.attr['use_locking']
            elif node.op == 'AssignAdd':
                node.op = 'Add'
                if 'use_locking' in node.attr: del node.attr['use_locking']
        
        converted_graph_def = graph_util.convert_variables_to_constants(sess, gd, output_node_names.split(","))
        tf.train.write_graph(converted_graph_def, args.output_dir, args.output_filename, as_text=False)
15reactions
mhaghighatcommented, Feb 15, 2017

BTW, this error also happens when I load the .pb model in Python:

ValueError: graph_def is invalid at node 'InceptionResnetV1/Conv2d_1a_3x3/BatchNorm/cond/AssignMovingAvg/Switch': Input tensor 'InceptionResnetV1/Conv2d_1a_3x3/BatchNorm/moving_mean:0' Cannot convert a tensor of type float32 to an input of type float32_ref.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Input 0 of node incompatible with expected float_ref.** - ...
I'm getting below exception while trying to import my optimized frozen graph. # read pb into graph_def with tf.gfile.GFile(pb_file, "rb") as ...
Read more >
Save, Load and Inference From TensorFlow 2.x Frozen Graph
In this blog post, I am going to show how to save, load, and run inference for frozen graphs in TensorFlow 2.x.
Read more >
C2000™ Piccolo™ Workshop
Code Composer Studio can automatically load the output file after a successful ... future knowlege, realize that a single code error can sometimes...
Read more >
incompatible with expected resource - TensorRT
I did the below before loading the model while converting my keras model to a tensorflow graph as per https://stackoverflow.com/a/52823701:
Read more >
Frequently asked Questions about Caml (expert)
Error message: a type is not compatible with itself ? * How polymorphism is introduced ? * What means '_a ? * A...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found