How to Classify Single Image using Loaded Net

That’s interesting. Would it be possible for you to share the images?
I would like to reproduce this issue and debug it if it’s reproducible.

Sure.

https://drive.google.com/open?id=13nhxiXjCDvua0fceAUYWP5pS1x-P0LHB

Thanks for the files!
I tried to reproduce this issue using 1.0.0a0+4c11dee and 1.0.0.dev20181130, but I got these results both times:

834
208
285
478

Thank for debugging. I’ve just tried with a prebuilt wheel of pytorch 1.0.0.dev20181204 and the results are:

834
208
285
478

Then the problem is related to my custom build, but there are neither compilation or runtime errors… any guess?

I’ll pull your build later and try to reproduce it with it.
Have you changed anything or can I just pull 37627a1?

Yes, exactly as it is in 37627a182ba7af6ee388338d06af5c69d7ba6c59

btw, these are my system specs:

PyTorch version: 1.0.0a0+37627a1
Is debug build: No
CUDA used to build PyTorch: 9.2.148

OS: Ubuntu 18.04.1 LTS
GCC version: (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0
CMake version: version 3.12.2

Python version: 2.7
Is CUDA available: Yes
CUDA runtime version: Could not collect
GPU models and configuration: GPU 0: GeForce GTX 950M
Nvidia driver version: 396.54
cuDNN version: Probably one of the following:
/usr/lib/x86_64-linux-gnu/libcudnn.so.7.4.1
/usr/lib/x86_64-linux-gnu/libcudnn_static_v7.a
/usr/local/MATLAB/MATLAB_Runtime/v94/bin/glnxa64/libcudnn.so.7.0.3
/usr/local/MATLAB/R2018a/bin/glnxa64/libcudnn.so.7.0.3
/usr/local/cuda-9.2/lib64/libcudnn.so
/usr/local/cuda-9.2/lib64/libcudnn.so.7
/usr/local/cuda-9.2/lib64/libcudnn.so.7.4.1
/usr/local/cuda-9.2/lib64/libcudnn_static.a
/usr/local/cuda-9.2/lib64/libcudnn_static_v7.a

Versions of relevant libraries:
[pip] Could not collect
[conda] magma-cuda92 2.4.0 1 pytorch
[conda] torch 1.0.0a0+37627a1 
[conda] torchvision 0.2.1

Thanks for your patience!
I could reproduce this issue in 37627a1.
After some debugging it looks like the input tensors are slightly different.
Here is an example of the diff images between 1.0.0a0+37627a1 and 1.0.0a0+4c11dee

0

It looks like some kind of shift, but nevertheless the model shouldn’t always output the same class.
Also, the model will predict class 918 for the following inputs:

  • random input (torch.randn(1, 3, 224, 224))
  • all ones
  • all zeros
  • some high positive value (e.g. 100)
  • some low negative value (e.g. -100)

I skimmed through the commits after 37627a1, but couldn’t identify any changes that might have fixed this bug.
Although this issue was apparently fixed in the current master, it might still be interesting to investigate.
CC @fmassa

1 Like

Using the given code below, which I am using to predict rather classify the image. I am getting a particular output which I have posted below. Which part of it is the prediction…

#imsize =100
loader = transforms.Compose([ transforms.ToTensor()])
from PIL import Image
def image_loader(image_name):
    """load image, returns cuda tensor"""
    image = Image.open(image_name)
    image = loader(image).float()
    #image = Variable(image, requires_grad=True)
    image = image.unsqueeze(0)  #this is for VGG, may not be needed for ResNet
    return image  #assumes that you're using GPU

image = image_loader(path)

net(image)

In my model I have used various print statements that is the reason behind getting the shapes after every layer.

torch.Size([1, 3, 100, 100])
torch.Size([1, 13, 100, 100])
torch.Size([1, 13, 50, 50])
torch.Size([1, 32, 46, 46])
torch.Size([1, 32, 23, 23])
tensor([[ 0.1016, -0.0470]], grad_fn=<AddmmBackward>)

So what should I do further??

Thanks works fine :heart:

Can I know what is Variable(…) here

Variables are deprecated since PyTorch 0.4 so you can use tensors now.
They were used for tensor operations, which should be tracked by Autograd, but this wrapper is not necessary anymore.

What is ‘loader’ in loader(image).float()?

They declared it at the top

loader = transforms.Compose([transforms.Scale(imsize), transforms.ToTensor()]
  1. one of them (model or input) is in cpu and the other is in GPU. Upload them to GPU using model = model. cuda(), image = image.
  2. The output that we get from pretrained models are unnormalized linear layer outputs. you can use F. softmax() to convert them to probabilities.
  3. expressHR