TensorFlow 1.x Protobuf Inference

Inference code for protobufs in TensorFlow 1.x:

import numpy as np
import tensorflow as tf

def load_graph(frozen_graph_filename):
    # We load the protobuf file from the disk and parse it to retrieve the 
    # unserialized graph_def
    with tf.gfile.GFile(frozen_graph_filename, "rb") as f:
        graph_def = tf.GraphDef()
        graph_def.ParseFromString(f.read())

    # Then, we import the graph_def into a new Graph and returns it 
    with tf.Graph().as_default() as graph:
        # Be careful about the name here, if set to some value, all node names will change.
        tf.import_graph_def(graph_def, name="") 
    return graph

graph = load_graph("frozen_graph_full.pb")

input_tensor = graph.get_tensor_by_name('lowres_input:0')
output_tensor = graph.get_tensor_by_name('inference/output/slice/BilateralSliceApply:0')
        
with tf.Session(graph=graph) as sess:
    y_out = sess.run(output_tensor, feed_dict={input_tensor: np.random.rand(1, 512, 512, 3)})
    print(y_out)