tensorflow - How to Retrain Inception's Final Layer for New Categories -
i used retraining example inception on tf retrain inception error if try classify image. used following code - code classification wrong or there problem memory allocation?
import tensorflow tf import sys # change see fit image_path = 'c:/tmp/test.jpg' # read in image_data image_data = tf.gfile.fastgfile(image_path, 'rb').read() # loads label file, strips off carriage return label_lines = [line.rstrip() line in tf.gfile.gfile("c:/tmp/output_labels.txt")] # unpersists graph file tf.gfile.fastgfile("c:/tmp/output_graph.pb", 'rb') f: graph_def = tf.graphdef() graph_def.parsefromstring(f.read()) _ = tf.import_graph_def(graph_def, name='') tf.session() sess: # feed image_data input graph , first prediction softmax_tensor = sess.graph.get_tensor_by_name('final_result:0') predictions = sess.run(softmax_tensor, \ {'decodejpeg/contents:0': image_data}) # sort show labels of first prediction in order of confidence top_k = predictions[0].argsort()[-len(predictions[0]):][::-1] 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 c:\tf_jenkins\home\workspace\release- win\device\gpu\os\windows\tensorflow\stream_executor\dso_loader.cc:135] opened cuda library cublas64_80.dll locally c:\tf_jenkins\home\workspace\release- win\device\gpu\os\windows\tensorflow\stream_executor\dso_loader.cc:135] opened cuda library cudnn64_5.dll locally c:\tf_jenkins\home\workspace\release- win\device\gpu\os\windows\tensorflow\stream_executor\dso_loader.cc:135] opened cuda library cufft64_80.dll locally c:\tf_jenkins\home\workspace\release- win\device\gpu\os\windows\tensorflow\stream_executor\dso_loader.cc:135] opened cuda library nvcuda.dll locally c:\tf_jenkins\home\workspace\release- win\device\gpu\os\windows\tensorflow\stream_executor\dso_loader.cc:135] 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"') 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"') 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"') 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"') 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"') 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"') 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"') 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"') 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"') 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"') 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"') unknown op: updatefertileslots c:\tf_jenkins\home\workspace\release- win\device\gpu\os\windows\tensorflow\core\common_runtime\gpu\gpu_device.cc:885] found device 0 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 c:\tf_jenkins\home\workspace\release-win\device\gpu\os\windows\tensorflow\core\common_runtime\gpu\gpu_device.cc:906] dma: 0 c:\tf_jenkins\home\workspace\release-win\device\gpu\os\windows\tensorflow\core\common_runtime\gpu\gpu_device.cc:916] 0: y 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 deprecated. cease 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 allocate 1.91gib. caller indicates not failure, may mean there performance gains if more memory 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
the problem human_string = label_lines[node_id]
; think you're indexing wrong array. can print values of top_k
, size of label_lines
make sure there's not indexing mistake in call argsort?
Comments
Post a Comment