bentrevett / pytorch-image-classification

Tutorials on how to implement a few key architectures for image classification using PyTorch and TorchVision.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

feedback an error

wwdok opened this issue · comments

Hi, dear author, thanks for the so detailed image classification tutorials ! I was running 5 - ResNet colab notebook, when it run to the training step, it happened following error :
image
Then i did change the view() to reshape() in calculate_topk_accuracy(), it turns out it can work, that is it, i just come to feedback an error ~

Oh, when it is going to finish training, it happens another error :
image

It is a little weird, i run the colab notebook again, those two errors didn't appear this time.
At the last step of ‘plot_filters`, i found some filters is purely black, what does this means ? It means these filters doesn't learn anything ? My dataset have 4 classes, each class has about 300 images, i used Resnet18 model to train 10 epochs, the accuracy achieves about 99%.
image

I have fixed the .view/.reshape error in master, but I'm unable to re-create the second error. Please let me know if you can reproduce it.

I am not 100% sure about the filters tending toward black. The first thing to check is if these filters are actually all zero or are just very small numbers. A filter going black would mean that it had learned to do this when fine-tuning, perhaps use the plot_filtered_images function to run the black filters over a few of the images in your dataset and see the results? If the black filters aren't actually zero then you might see something, but if they are zero then you won't see anything.

The second error happended randomly in my situation( the 1st time and 2nd time happened, the 3rd time was ok), i don't quite know what is the key step to reproduce it.
As you suggestted, i printed out the filters, and found these black filters actually have very small value, one of balck filter is :

        [[[-7.0826e-08, -6.4306e-08, -7.3806e-08,  ..., -9.8000e-08,
           -1.0905e-07, -8.3421e-08],
          [-6.1125e-09,  2.0613e-09, -8.0922e-09,  ..., -4.9840e-08,
           -4.3836e-08, -3.0538e-09],
          [ 7.1953e-08,  7.5616e-08,  5.9282e-08,  ..., -9.7509e-09,
           -1.0951e-09,  4.2442e-08],
          ...,
          [ 9.5889e-08,  1.0039e-07,  7.9817e-08,  ..., -1.7491e-08,
           -4.7666e-08, -1.3265e-08],
          [ 1.2904e-07,  1.4762e-07,  1.7477e-07,  ...,  1.3233e-07,
            1.0628e-07,  9.3316e-08],
          [ 1.2558e-07,  1.3644e-07,  1.8431e-07,  ...,  2.1399e-07,
            1.7710e-07,  1.7166e-07]],

         [[-1.2690e-07, -9.6139e-08, -1.0372e-07,  ..., -1.1808e-07,
           -1.3309e-07, -1.0820e-07],
          [-5.7412e-08, -2.5055e-08, -3.0115e-08,  ..., -7.2922e-08,
           -6.7022e-08, -2.2574e-08],
          [ 2.1813e-08,  4.8608e-08,  3.1222e-08,  ..., -1.8694e-08,
           -7.9591e-09,  3.9750e-08],
          ...,
          [ 5.6013e-08,  7.5526e-08,  4.4496e-08,  ..., -4.4128e-08,
           -5.9930e-08, -1.8247e-08],
          [ 7.7614e-08,  9.8348e-08,  1.0455e-07,  ...,  6.3272e-08,
            4.1781e-08,  4.5901e-08],
          [ 5.9834e-08,  7.1006e-08,  9.0437e-08,  ...,  1.1654e-07,
            8.7550e-08,  9.8837e-08]],

         [[-4.3810e-08,  1.3270e-08,  7.8275e-09,  ..., -5.8804e-09,
           -2.6217e-08, -1.5649e-08],
          [ 4.1700e-08,  1.0778e-07,  1.0946e-07,  ...,  7.6403e-08,
            7.1450e-08,  9.7615e-08],
          [ 1.0436e-07,  1.6586e-07,  1.5933e-07,  ...,  1.3517e-07,
            1.3487e-07,  1.6449e-07],
          ...,
          [ 9.8763e-08,  1.5072e-07,  1.2547e-07,  ...,  6.8316e-08,
            6.8382e-08,  1.1367e-07],
          [ 9.1435e-08,  1.3576e-07,  1.3793e-07,  ...,  1.1678e-07,
            1.1723e-07,  1.4394e-07],
          [ 6.2183e-08,  8.8184e-08,  1.0456e-07,  ...,  1.3941e-07,
            1.3333e-07,  1.5844e-07]]],

You can see that the magnitude is e-07 and e-08 while the magnititude of average filters is e-01 e-02 e-03 .

Then the output of plot_filtered_images is following screenshot, from my posted sreenshot above, filter3 and filter5 are the black filters, their according result are the two colume indicated by the red rectangle , it seems they just turn the image into grayscale.
image
Thanks for your inspiration, now i have deep understanding of CNN !