pytorch-image-classification
pytorch-image-classification copied to clipboard
value error
hello, Whenever I am trying to run with iterator it is showing error
ValueError Traceback (most recent call last)
ValueError: too many values to unpack (expected 2)
For which notebook is this? Only the first 3 notebooks should be considered complete, the rest are in the process of being re-written.
The model should return a tuple of tensors, in the first three we are returning both the final output and an intermediate layer so we can plot it with PCA/t-SNE. The error you are getting is due to the model only returning a single tensor, i.e. your model's forward
method should end with return x, h
, but yours is only doing return x
(or something similar).
I have executed the resnet.ipynb file with my own dataset. The model has run successfully but I want to visualize the predicted labels as well as confusion matrix as it is shown in the "Lenet.ipynb" tutorial. So, whenever I am trying to execute "images, labels, probs = get_predictions(model, test_iterator)" this line of code it is throwing error like this,
RuntimeError: size mismatch, m1: [40 x 2048], m2: [512 x 2] at C:/w/1/s/tmp_conda_3.6_095855/conda/conda-bld/pytorch_1579082406639/work/aten/src\THC/generic/THCTensorMathBlas.cu:290.
and when I replace the test iterator with valid iterator "images, labels, probs = get_predictions(model, valid_iterator)" it is throwing the previous error
ValueError Traceback (most recent call last)
ValueError: too many values to unpack (expected 2)
In the ResNet model, change the last few lines of the forward
method to:
h = out.view(out.shape[0], -1)
out = self.fc(h)
return out, h
changing these line of code is throwing another error AttributeError: 'tuple' object has no attribute 'log_softmax'
Can you upload the notebook to a GitHub gist? I'll have a quick look at it.
I have uploaded the notebook as a Github gist.
On Mon, Apr 6, 2020 at 7:38 PM Ben Trevett [email protected] wrote:
Can you upload the notebook to a GitHub gist? I'll have a quick look at it.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/bentrevett/pytorch-image-classification/issues/2#issuecomment-609817725, or unsubscribe https://github.com/notifications/unsubscribe-auth/AL4XZOCYAEZLKAVTRREVXBLRLHO5TANCNFSM4MBF7VZQ .
-- With Regards, Rukhmini Roy
In the train
and evaluate
functions you need to change fx = model(x)
to fx, _ = model(x)
.
In both the ResNet18
and ResNet34
models, within the forward
method you need to change:
out = out.view(out.shape[0], -1)
out = self.fc(out)
return out
to
h = out.view(out.shape[0], -1)
out = self.fc(h)
return out, h
Thanks for all the help Ben, but still I am getting the same runtime error while using test iterator.
On Mon, Apr 6, 2020 at 9:41 PM Ben Trevett [email protected] wrote:
In the train and evaluate functions you need to change fx = model(x) to fx, _ = model(x).
In both the ResNet18 and ResNet34 models, within the forward method you need to change:
out = out.view(out.shape[0], -1) out = self.fc(out)return out
to
h = out.view(out.shape[0], -1) out = self.fc(h)return out, h
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/bentrevett/pytorch-image-classification/issues/2#issuecomment-609889365, or unsubscribe https://github.com/notifications/unsubscribe-auth/AL4XZODYZY4TEFUQ7C2ESRDRLH5J3ANCNFSM4MBF7VZQ .
-- With Regards, Rukhmini Roy
https://gist.github.com/bentrevett/3f899ce17781d91e8c9dbdad2c1a1cc9
Here is the code for the AlexNet notebook but with the model changed to ResNet18 - might be useful for you.
This also throwing the same runtime error. I am using gray scale images to train and test the network. Will that be a problem?
On Mon, Apr 6, 2020 at 11:40 PM Ben Trevett [email protected] wrote:
https://gist.github.com/bentrevett/3f899ce17781d91e8c9dbdad2c1a1cc9
Here is the code for the AlexNet notebook but with the model changed to ResNet18 - might be useful for you.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/bentrevett/pytorch-image-classification/issues/2#issuecomment-609952914, or unsubscribe https://github.com/notifications/unsubscribe-auth/AL4XZOE3UH2FAG5K5ZHJ373RLILKDANCNFSM4MBF7VZQ .
-- With Regards, Rukhmini Roy