def patch_graph()

in tensorflow-examples-legacy/label_image/download.py [0:0]


def patch_graph():
  """Create graph.pb that applies the model in URL to raw image bytes."""
  with tf.Graph().as_default() as g:
    input_image, image_normalized = create_graph_to_decode_and_normalize_image()
    original_graph_def = tf.GraphDef()
    with open(os.path.join(LOCAL_DIR, 'graph.pb')) as f:
      original_graph_def.ParseFromString(f.read())
    softmax = tf.import_graph_def(
        original_graph_def,
        name='inception',
        input_map={GRAPH_INPUT_TENSOR: image_normalized},
        return_elements=[GRAPH_PROBABILITIES_TENSOR])
    # We're constructing a graph that accepts a single image (as opposed to a
    # batch of images), so might as well make the output be a vector of
    # probabilities, instead of a batch of vectors with batch size 1.
    output_probabilities = tf.squeeze(softmax, name='probabilities')
    # Overwrite the graph.
    with open(os.path.join(LOCAL_DIR, 'graph.pb'), 'w') as f:
      f.write(g.as_graph_def().SerializeToString())
    print('------------------------------------------------------------')
    print('MODEL GRAPH  : graph.pb')
    print('LABELS       : labels.txt')
    print('INPUT TENSOR : %s' % input_image.op.name)
    print('OUTPUT TENSOR: %s' % output_probabilities.op.name)