Python Forum
NameError: name 'predicted_labels' is not defined - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Data Science (https://python-forum.io/forum-44.html)
+--- Thread: NameError: name 'predicted_labels' is not defined (/thread-41253.html)



NameError: name 'predicted_labels' is not defined - hobbyist - Dec-07-2023

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?


RE: NameError: name 'predicted_labels' is not defined - buran - Dec-07-2023

check the full code in the github repo
https://github.com/aryan109/medium/blob/master/Custom_Image_Classification/Custom_image_clasification.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


RE: NameError: name 'predicted_labels' is not defined - hobbyist - Dec-08-2023

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?