Python Forum
NameError: name 'predicted_labels' is not defined
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
NameError: name 'predicted_labels' is not defined
#1
Hello! I am trying to run the code from this tutorial: link-for-the-code

but on this part:

val_image_batch, val_label_batch = next(iter(valid_generator))

tf_model_predictions = model.predict(val_image_batch)
print("Prediction results shape:", tf_model_predictions.shape)
plt.figure(figsize=(10,9))
plt.subplots_adjust(hspace=0.5)
for n in range((len(predicted_labels)-2)): # here is the problem
 plt.subplot(6,5,n+1)
 plt.imshow(val_image_batch[n])
 color = "green" if predicted_ids[n] == true_label_ids[n] else "red"
 plt.title(predicted_labels[n].title(), color=color)
 plt.axis('off')
_ = plt.suptitle("Model predictions (green: correct, red: incorrect)")
I get this error:

Error:
NameError: name 'predicted_labels' is not defined
I am searching all day in order to find a solution via google...Nothing yet!! Has anyone, any idea how to solve it?
Reply
#2
check the full code in the github repo
https://github.com/aryan109/medium/blob/...tion.ipynb

The link is in the article. It looks like not all cells were included in the article, e.g. at least the second to last cells is missing in the article and there predicted_labels is defined
hobbyist likes this post
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
One more question... I am trying to download a ready model from here: link but the antivirus prevents me from this action.... What is going on? Is there any alternative link to download it?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  NameError: name 'rand' is not defined Truman 7 6,849 Jun-17-2020, 07:14 PM
Last Post: Truman
  NameError mlab not defined PythonAndArduino 5 7,033 Nov-08-2017, 06:47 PM
Last Post: nilamo
  Python : NameError: name 'total_wait' is not defined carla 3 5,280 Jun-04-2017, 05:49 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020