代码执行时出现错误
使用tf.compat.v2.io.gfile.GFile(PATH_TO_CKPT,'rb')作为fid: serialized_graph = fid.read()
有人可以帮我这个忙吗?我无法读取可可数据集文件。
import numpy as np
import os
os.chdir('C:\\Tensorflow1\\models\\research\\object_detection')
import six.moves.urllib as urllib
import sys
import tarfile
import urllib.request
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 utils import ops as utils_ops
from object_detection.utils import label_map_util
from object_detection.utils import visualization_utils as vis_util
if tf.__version__<'1.4.0':
raise ImportError('Please Upgrade Tensorflow')
get_ipython().run_line_magic('matplotlib','inline')
MODEL_NAME="ssd_mobilenet_v1_coco_2018_01_28"
MODEL_FILE=MODEL_NAME+".tar.gz"
DOWNLOAD_BASE = "http://download.tensorflow.org/models/object_detection/"
PATH_TO_CKPT=MODEL_FILE+"/frozen_interface_graph.pb"
PATH_TO_LABELS=os.path.join('data','mscoco_label_map.pbtext')
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.compat.v1.GraphDef()
with tf.compat.v2.io.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='')