2017-08-14 1 views
0

J'ai utilisé l'exemple de recyclage pour la création sur TF Retrain Inception mais j'obtiens une erreur si j'essaie de classer une image. J'ai utilisé le code suivant - le code de classification est-il incorrect ou y a-t-il un problème avec mon allocation de mémoire?Comment redéfinir le calque final de l'initialisation pour de nouvelles catégories

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)) 

errormessage:

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 
+0

pourquoi la downvote? – user3483676

Répondre

1

Le problème est avec human_string = label_lines[node_id]; Je pense que vous indexez dans le mauvais tableau. Pouvez-vous imprimer les valeurs de top_k et la taille de label_lines pour vous assurer qu'il n'y a pas d'erreur d'indexation dans l'appel à argsort?

+0

Salut. Oui, je l'ai changé pour imprimer (label_lines, predictions [0]) et enlevé la boucle for. Ça fonctionne maintenant. THX. – user3483676