bayesian-neural-network-mnist
bayesian-neural-network-mnist copied to clipboard
Possible minor fix needed in test_batch(...)
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.
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
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,2828)) total += labels.size(0) correct += (predicted == labels.numpy()).sum().item()
Thanks. I don't get this error. Is this a version issue?
Plausible. I was unable to reproduce this issue with PyTorchv1 from conda as well.
I suspect this is from minor version 1.x.x differences. Let's wait and see if someone else come across this error as well?
On Tue, 5 Feb 2019 at 10:50, Paras Chopra [email protected] wrote:
Thanks. I don't get this error. Is this a version issue?
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/paraschopra/bayesian-neural-network-mnist/issues/3#issuecomment-460516574, or mute the thread https://github.com/notifications/unsubscribe-auth/ADGaPVBNyWmBpGLLRJxt-OjPBXsqO5dYks5vKRSrgaJpZM4Yxvde .
Not blocking, as I have found a workaround.