Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible minor fix needed in test_batch(...) #3

Open
NirantK opened this issue Nov 25, 2018 · 5 comments
Open

Possible minor fix needed in test_batch(...) #3

NirantK opened this issue Nov 25, 2018 · 5 comments

Comments

@NirantK
Copy link

NirantK commented Nov 25, 2018

When working with random data,

test_batch(images_random, labels_random)

multiple runs interrupted with this small snafu:

Summary
Total images:  100
Predicted for:  0

---------------------------------------------------------------------------
ZeroDivisionError                         Traceback (most recent call last)
<timed eval> in <module>

<ipython-input-17-df814c720b20> in test_batch(images, labels, plot)
     81         print("Total images: ",len(labels))
     82         print("Predicted for: ",predicted_for_images)
---> 83         print("Accuracy when predicted: ",correct_predictions/predicted_for_images)
     84 
     85     return len(labels), correct_predictions, predicted_for_images

ZeroDivisionError: division by zero

Consider add a try-except block to catch the ZeroDivisionError and handle this?

Of course, this still drives your overall point correctly - but for someone simply skimming the code this might look like a bug.

@NirantK
Copy link
Author

NirantK commented Nov 25, 2018

In the same vein, maybe forced predictions should not be called Real? That makes it sound like Ground Truth - which is misleading.

Real: 3 --> Forced Prediction: 3

This is with reference to the not-MNIST dataset inference

@Bruno-Hanzen
Copy link

Bruno-Hanzen commented Jan 26, 2019

I have executed the code under Spyder, with Pytorch v1.
I got an error in the following part:
for j, data in enumerate(test_loader):
images, labels = data
predicted = predict(images.view(-1,2828))
total += labels.size(0)
correct += (predicted == labels).sum().item()
"predicted"_ is a numpy array, while labels is a PyTorch tensor.
Corrected it by adding .numpy() to get a Numpy array.
for j, data in enumerate(test_loader):
images, labels = data
predicted = predict(images.view(-1,28
28))
total += labels.size(0)
correct += (predicted == labels.numpy()).sum().item()

@paraschopra
Copy link
Owner

Thanks. I don't get this error. Is this a version issue?

@NirantK
Copy link
Author

NirantK commented Feb 5, 2019 via email

@Bruno-Hanzen
Copy link

Not blocking, as I have found a workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants