0

我在TF Retrain Inception上使用了再训练示例进行 inception,但如果我尝试对图像进行分类,则会出现错误。我使用了以下代码 - 分类代码是错误的还是我的内存分配有问题?

import tensorflow as tf
import sys

# change this as you see fit
image_path = 'C:/tmp/test.jpg'

# 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("C:/tmp/output_labels.txt")]

# Unpersists graph from file
with tf.gfile.FastGFile("C:/tmp/output_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})

# Sort to show labels of first prediction in order of confidence
top_k = predictions[0].argsort()[-len(predictions[0]):][::-1]

for node_id in top_k:
    human_string = label_lines[node_id]
    score = predictions[0][node_id]
    print('%s (score = %.5f)' % (human_string, score))

错误信息:

C:\Users\Murph\Documents\Python Scripts\RETRAIN_INCEPTION>python classify.py
I c:\tf_jenkins\home\workspace\release-
win\device\gpu\os\windows\tensorflow\stream_executor\dso_loader.cc:135] 
successfully opened CUDA library cublas64_80.dll locally
I c:\tf_jenkins\home\workspace\release-
win\device\gpu\os\windows\tensorflow\stream_executor\dso_loader.cc:135] 
successfully opened CUDA library cudnn64_5.dll locally
I c:\tf_jenkins\home\workspace\release-
win\device\gpu\os\windows\tensorflow\stream_executor\dso_loader.cc:135] 
successfully opened CUDA library cufft64_80.dll locally
I c:\tf_jenkins\home\workspace\release-
win\device\gpu\os\windows\tensorflow\stream_executor\dso_loader.cc:135] 
successfully opened CUDA library nvcuda.dll locally
I c:\tf_jenkins\home\workspace\release-
win\device\gpu\os\windows\tensorflow\stream_executor\dso_loader.cc:135] 
successfully opened CUDA library curand64_80.dll locally
E c:\tf_jenkins\home\workspace\release-
win\device\gpu\os\windows\tensorflow\core\framework\op_kernel.cc:943] 
OpKernel ('op: "BestSplits" device_type: "CPU"') for unknown op: BestSplits
E c:\tf_jenkins\home\workspace\release-
win\device\gpu\os\windows\tensorflow\core\framework\op_kernel.cc:943] 
OpKernel ('op: "CountExtremelyRandomStats" device_type: "CPU"') for unknown 
op: CountExtremelyRandomStats
E c:\tf_jenkins\home\workspace\release-
win\device\gpu\os\windows\tensorflow\core\framework\op_kernel.cc:943] 
OpKernel ('op: "FinishedNodes" device_type: "CPU"') for unknown op: 
FinishedNodes
E c:\tf_jenkins\home\workspace\release-
win\device\gpu\os\windows\tensorflow\core\framework\op_kernel.cc:943] 
OpKernel ('op: "GrowTree" device_type: "CPU"') for unknown op: GrowTree
E c:\tf_jenkins\home\workspace\release-
win\device\gpu\os\windows\tensorflow\core\framework\op_kernel.cc:943] 
OpKernel ('op: "ReinterpretStringToFloat" device_type: "CPU"') for unknown 
op: ReinterpretStringToFloat
E c:\tf_jenkins\home\workspace\release-
win\device\gpu\os\windows\tensorflow\core\framework\op_kernel.cc:943] 
OpKernel ('op: "SampleInputs" device_type: "CPU"') for unknown op: 
SampleInputs
E c:\tf_jenkins\home\workspace\release-
win\device\gpu\os\windows\tensorflow\core\framework\op_kernel.cc:943] 
OpKernel ('op: "ScatterAddNdim" device_type: "CPU"') for unknown op: 
ScatterAddNdim
E c:\tf_jenkins\home\workspace\release-
win\device\gpu\os\windows\tensorflow\core\framework\op_kernel.cc:943] 
OpKernel ('op: "TopNInsert" device_type: "CPU"') for unknown op: TopNInsert
E c:\tf_jenkins\home\workspace\release-
win\device\gpu\os\windows\tensorflow\core\framework\op_kernel.cc:943] 
OpKernel ('op: "TopNRemove" device_type: "CPU"') for unknown op: TopNRemove
E c:\tf_jenkins\home\workspace\release-
win\device\gpu\os\windows\tensorflow\core\framework\op_kernel.cc:943] 
OpKernel ('op: "TreePredictions" device_type: "CPU"') for unknown op: 
TreePredictions
E c:\tf_jenkins\home\workspace\release-
win\device\gpu\os\windows\tensorflow\core\framework\op_kernel.cc:943] 
OpKernel ('op: "UpdateFertileSlots" device_type: "CPU"') for unknown op: 
UpdateFertileSlots
I c:\tf_jenkins\home\workspace\release-


    win\device\gpu\os\windows\tensorflow\core\common_runtime\gpu\gpu_device.cc:885] Found device 0 with properties:
    name: GeForce GTX 760
major: 3 minor: 0 memoryClockRate (GHz) 1.137
pciBusID 0000:01:00.0
Total memory: 2.00GiB
Free memory: 1.65GiB
I c:\tf_jenkins\home\workspace\release-win\device\gpu\os\windows\tensorflow\core\common_runtime\gpu\gpu_device.cc:906] DMA: 0
I c:\tf_jenkins\home\workspace\release-win\device\gpu\os\windows\tensorflow\core\common_runtime\gpu\gpu_device.cc:916] 0:   Y
I c:\tf_jenkins\home\workspace\release-win\device\gpu\os\windows\tensorflow\core\common_runtime\gpu\gpu_device.cc:975] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 760, pci bus id: 0000:01:00.0)
W c:\tf_jenkins\home\workspace\release-win\device\gpu\os\windows\tensorflow\core\framework\op_def_util.cc:332] Op BatchNormWithGlobalNormalization is deprecated. It will cease to work in GraphDef version 9. Use tf.nn.batch_normalization().
W c:\tf_jenkins\home\workspace\release-win\device\gpu\os\windows\tensorflow\core\common_runtime\bfc_allocator.cc:217] Ran out of memory trying to allocate 1.91GiB. The caller indicates that this is not a failure, but may mean that there could be performance gains if more memory is available.
call/nput/n (score = 0.61942)
Traceback (most recent call last):
  File "classify_v2.py", line 33, in <module>
    human_string = label_lines[node_id]
IndexError: list index out of range
4

1 回答 1

1

问题在于human_string = label_lines[node_id];我认为您正在索引错误的数组。您能否打印 的值top_k和大小label_lines以确保在调用 argsort 时没有索引错误?

于 2017-08-15T20:54:00.777 回答