【发布时间】:2021-09-21 20:07:58
【问题描述】:
我正在使用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='')
由于它不适用于TensorFlow2,我将代码转换为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='')
但它会触发以下错误:
with detection_graph.as_default():
AttributeError: as_default
有谁知道如何解决这个问题?
【问题讨论】:
标签: python tensorflow tensorflow2.0