od_graph_def = tf.GraphDef() AttributeError: 模块“tensorflow"没有属性“GraphDef" [英] od_graph_def = tf.GraphDef() AttributeError: module 'tensorflow' has no attribute 'GraphDef'

查看:26
本文介绍了od_graph_def = tf.GraphDef() AttributeError: 模块“tensorflow"没有属性“GraphDef"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一台 mac,我使用的是 tensorflow 2.0、python 3.7.我正在关注为实时应用程序创建对象检测模型的教程.但我收到以下错误:

I have a mac and I am using tensorflow 2.0, python 3.7. I am following the tutorial for creating an object detection model for real-time application. but i am getting the following error:

下载/模型/研究/object_detection/object_detection_tutorial.py",第 43 行,在od_graph_def = tfod_graph_def = tf.GraphDef()

"Downloads/models/research/object_detection/object_detection_tutorial.py", line 43, in od_graph_def = tf od_graph_def = tf.GraphDef()

AttributeError: 模块tensorflow"没有属性GraphDef"

AttributeError: module 'tensorflow' has no attribute 'GraphDef'

以下是教程链接:

我检查了环境,我已经在anaconda中有了tensorflow环境

I checked the environment and I already have tensorflow environment in anaconda

import tensorflow as tf
import zipfile

from collections import defaultdict
from io import StringIO
from matplotlib import pyplot as plt
from PIL import Image

sys.path.append("..")
from object_detection.utils import ops as utils_ops


from utils import label_map_util

from utils import visualization_utils as vis_util

MODEL_NAME = 'ssd_mobilenet_v1_coco_2017_11_17'
MODEL_FILE = MODEL_NAME + '.tar.gz'
DOWNLOAD_BASE = 'http://download.tensorflow.org/models/object_detection/'

PATH_TO_CKPT = MODEL_NAME + '/frozen_inference_graph.pb'

PATH_TO_LABELS = os.path.join('data', 'mscoco_label_map.pbtxt')

NUM_CLASSES = 90


opener = urllib.request.URLopener()
opener.retrieve(DOWNLOAD_BASE + MODEL_FILE, MODEL_FILE)
tar_file = tarfile.open(MODEL_FILE)
for file in tar_file.getmembers():
  file_name = os.path.basename(file.name)
  if 'frozen_inference_graph.pb' in file_name:
    tar_file.extract(file, os.getcwd())

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

推荐答案

是的,T2.0 中的语法已更改.这是正确的部分:

Yeah, the syntax has changed in T2.0. Here's the correct piece:

tf.compat.v1.GraphDef()   # -> instead of tf.GraphDef()
tf.compat.v2.io.gfile.GFile()   # -> instead of tf.gfile.GFile()

这篇关于od_graph_def = tf.GraphDef() AttributeError: 模块“tensorflow"没有属性“GraphDef"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆