1

I was running this code with TensorFlow1

detection_graph = tf.Graph()
with detection_graph.as_default():
  od_graph_def = tf.GraphDef()
  with tf.gfile.GFile(PATH_TO_FROZEN_GRAPH, 'rb') as fid:
    serialized_graph = fid.read()
    od_graph_def.ParseFromString(serialized_graph)
    tf.import_graph_def(od_graph_def, name='')

Since it does not work on TensorFlow2 I converted the code to According to this:

detection_graph = tf.compat.v1.GraphDef()
with detection_graph.as_default():
  od_graph_def = tf.compat.v1.GraphDef()
  with tf.compat.v2.io.gfile.GFile(PATH_TO_FROZEN_GRAPH, 'rb') as fid:
    serialized_graph = fid.read()
    od_graph_def.ParseFromString(serialized_graph)
    tf.import_graph_def(od_graph_def, name='')

but it trigger the following error :

with detection_graph.as_default():
AttributeError: as_default

Do anyone know how to fix this ?

TourEiffel
  • 4,034
  • 2
  • 16
  • 45

1 Answers1

2

In Tensorflow 1 use like,

import tensorflow as tf
print(tf.__version__)
detection_graph = tf.compat.v1.get_default_graph()
with detection_graph.as_default():
  od_graph_def = tf.GraphDef()