0
我使用初始v3模型imageNet形状与张量流进行图像分类。该程序旨在对单个图像进行分类,因此我试图对其进行修改以对测试图像数据库进行分类。它归类图像很好,但在约20幅图像到达返回我下面的错误:File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 1912, in as_graph_def raise ValueError("GraphDef cannot be larger than 2GB.") ValueError: GraphDef cannot be larger than 2GB.
使用张量流程的错误图形Def不能大于2GB
下面是我修改的图像标签代码:
# -*- coding: utf-8 -*-
import os, sys
import time
import tensorflow as tf
def chargement_image(path):
image = []
image = os.listdir(path)
return image
resultat = []
best = []
nbr = 0
som = 0
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
start_time = time.time()
# Chargement de la base de test
test_path = sys.argv[1]
list_img = chargement_image(test_path)
for i in range(len(list_img)):
image_path = test_path+list_img[i]
# Read in the image_data
image_data = tf.gfile.FastGFile(image_path, 'rb').read()
# Loads label file, strips off carriage return
label_lines = [line.rstrip() for line
in tf.gfile.GFile("retrained_labels.txt")]
# Unpersists graph from file
with tf.gfile.FastGFile("retrained_graph.pb", 'rb') as f:
graph_def = tf.GraphDef()
graph_def.ParseFromString(f.read())
tf.import_graph_def(graph_def, name='')
with tf.Session() as sess:
# Feed the image_data as input to the graph and get first prediction
softmax_tensor = sess.graph.get_tensor_by_name('final_result:0')
predictions = sess.run(softmax_tensor, \
{'DecodeJpeg/contents:0': image_data})
#print(len(predictions))
# Trier pour afficher les étiquettes de la première prédiction par ordre de bon taux de classement
top_k = predictions[0].argsort()[-len(predictions[0]):][::-1]
#print(top_k)
for node_id in top_k:
human_string = label_lines[node_id]
score = predictions[0][node_id]
resultat.append(score)
print('%s (score = %.5f)' % (human_string, score))
#print(score)
nbr += 1
best.append(resultat[0])
del resultat[:]
#print(best)
print(nbr)
print("=========================================")
#print(best)
#print(nbr)
for i in range(len(best)):
som += best[i]
taux_precision = float(100. * som/nbr)
print 'Precision: ' + str(taux_precision) + '%'
print("--- %s seconds ---" % (time.time() - start_time))