Closed nahcyrret closed 6 years ago
I am getting a similar Key error. KeyError: "The name 'DecodeJpeg/contents:0' refers to a Tensor which does not exist. The operation, 'DecodeJpeg/contents', does not exist in the graph."
@nahcyrret : Did you resolve it?
I was able to resolve it. As it turns out, with TF later versions onwards opn:DecodeJpeg was replaced by 'Placeholder'. So, if you update the input_layer command, it should work.
Reference Link: https://stackoverflow.com/questions/45660439/the-name-decodejpeg-contents0-refers-to-a-tensor-which-does-not-exist
Sample code of How to Run Retrained model: https://www.tensorflow.org/tutorials/image_retraining
python label_image.py \ --graph=/tmp/output_graph.pb --labels=/tmp/output_labels.txt \ --input_layer=Placeholder \ --output_layer=final_result \ --image=$HOME/flower_photos/daisy/21652746_cc379e0eea_m.jpg
Hi ashwinravishan I have the following part run with error as well. Put each testing image into a sub folder corresponding to its label after converting to JPG format
for img in tqdm(test.values):
filename=img[0]
label=img[1]
src=os.path.join(data_root,'test_img',filename+'.png')
label_dir=os.path.join(data_root,'test',label)
dest=os.path.join(label_dir,filename+'.jpg')
im=Image.open(src)
rgb_im=im.convert('RGB')
if not os.path.exists(label_dir):
os.makedirs(label_dir)
rgb_im.save(dest)
if not os.path.exists(os.path.join(data_root,'test2',label)):
os.makedirs(os.path.join(data_root,'test2',label))
rgb_im.save(os.path.join(data_root,'test2',label,filename+'.jpg'))
IndexError Traceback (most recent call last)
Hi. Will have to check. This seems to be a compatibility issue (you're probably using an updated library that isn't back-compatible).
On Tue, Jul 3, 2018, 7:06 PM nahcyrret notifications@github.com wrote:
Hi ashwinravishan I have the following part run with error as well. Put each testing image into a sub folder corresponding to its label after converting to JPG format
for img in tqdm(test.values): filename=img[0] label=img[1] src=os.path.join(data_root,'test_img',filename+'.png') label_dir=os.path.join(data_root,'test',label) dest=os.path.join(label_dir,filename+'.jpg') im=Image.open(src) rgb_im=im.convert('RGB') if not os.path.exists(label_dir): os.makedirs(label_dir) rgb_im.save(dest) if not os.path.exists(os.path.join(data_root,'test2',label)): os.makedirs(os.path.join(data_root,'test2',label)) rgb_im.save(os.path.join(data_root,'test2',label,filename+'.jpg')) 0%| | 0/1732 [00:00<?, ?it/s]
IndexError Traceback (most recent call last) in () 1 for img in tqdm(test.values): 2 filename=img[0] ----> 3 label=img[1] 4 src=os.path.join(data_root,'test_img',filename+'.png') 5 label_dir=os.path.join(data_root,'test',label)
IndexError: index 1 is out of bounds for axis 0 with size 1
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/wisdal/Image-classification-transfer-learning/issues/1#issuecomment-402341677, or mute the thread https://github.com/notifications/unsubscribe-auth/AfTCAfhwrIRz78hKi1r34yCUa2-WKsTKks5uDCMSgaJpZM4Uufgq .
Thanks @ashwinravishankar for your suggestion. But which retrain.py file and inception model are you guys using?
@nahcyrret It will help if you can print variable img for us to see. tqdm(test.values) normally outputs an array of two columns; img should therefore have 2 fields.
I just run the retrain.py provided here. Is the inception model automatically downloaded? python -m retrain \ --bottleneck_dir=tf_files/bottlenecks \ --model_dir=tf_files/models/product \ --summaries_dir=tf_files/training_summaries/product \ --output_graph=tf_files/retrained_graph.pb \ --output_labels=tf_files/retrained_labels.txt \ --image_dir=train2
print(img) ['test_1000a']
@wisdal : I am using the retrain.py from tensorflow's master git repository.
Link: https://github.com/tensorflow/hub/blob/master/examples/image_retraining/retrain.py
I assume it uses the Inception V3 model.
@ashwinravishankar That makes sense: they updated the retrain script to use "placeholder" as graph name. I didn't update the script in my repository to avoid this confusion and incompatibility.
@nahcyrret That's very strange; you're the first reporting this issue. @ashwinravishankar did you face a similar issue?
Closing this issue.
I have run the retain and edit the final code of the test notebook as below. It run with keyerror. What this final code is supposed to do? I found the photos in test_img are png. Is it necessary to convert to jpg first? The code in test does not include the conversion. Is there way of showing the classification result using the test photos?
src=os.path.join('.','test_img') dest=os.path.join('.','test_img2') labels='tf_files/retrained_labels.txt' graph='tf_files/retrained_graph.pb' input_layer='DecodeJpeg/contents:0' output_layer='final_result:0' num_top_predictions=1 labels = load_labels(labels) load_graph(graph) run_graph(src,dest,labels,input_layer,output_layer,num_top_predictions)
KeyError Traceback (most recent call last) ~/anaconda3/envs/tensorflow/lib/python3.6/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance) 3062 try: -> 3063 return self._engine.get_loc(key) 3064 except KeyError:
pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
KeyError: 0