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

Error in trying to use for the first time #1

Closed
chmaz opened this issue Jul 24, 2017 · 5 comments
Closed

Error in trying to use for the first time #1

chmaz opened this issue Jul 24, 2017 · 5 comments

Comments

@chmaz
Copy link

chmaz commented Jul 24, 2017

Hello,

I am a beginner in python and pyTorch and am trying to use your densenet efficient implementation on a different dataset than CIFAR (images are 80 pixels wide, instead of 32). I use a windows 10 laptop with the experimental pyTorch port on Windows by peterjc123 (see pytorch/pytorch#494).

I have incorporated your DenseNetEfficient model in a training script adapted from andreasveit's densenet implementation for pyTorch and replaced the CIFAR datasets loaders with datasets ImageFolder as follows:
train_loader = torch.utils.data.DataLoader(

datasets.CIFAR10('../data', train=True, download=True,

transform=transform_train),

    datasets.ImageFolder(root=args.dataroot + '/train', transform=transform_train), batch_size=args.batch_size, shuffle=True, **kwargs)

When launching the training script; I get a cryptic error (for me):

Traceback (most recent call last):
File "train.py", line 312, in
main()
File "train.py", line 153, in main
train(train_loader, model, criterion, optimizer, epoch)
File "train.py", line 185, in train
output = model(input_var)
File "D:\deepLearning\Anaconda\lib\site-packages\torch\nn\modules\module.py", line 206, in call
result = self.forward(*input, **kwargs)
File "D:\deepLearning\densenet\densenetEfficient.py", line 213, in forward
out = self.classifier(out)
File "D:\deepLearning\Anaconda\lib\site-packages\torch\nn\modules\module.py", line 206, in call
result = self.forward(*input, **kwargs)
File "D:\deepLearning\Anaconda\lib\site-packages\torch\nn\modules\linear.py", line 54, in forward
return self.backend.Linear.apply(input, self.weight, self.bias)
File "D:\deepLearning\Anaconda\lib\site-packages\torch\nn_functions\linear.py", line 12, in forward
output.addmm
(0, 1, input, weight.t())
RuntimeError: size mismatch at d:\downloads\pytorch-master-1\torch\lib\thc\generic/THCTensorMathBlas.cu:243

I am surely doing something wrong but searched a lot and did not find anything,

Any recommendation would be welcome,

Thanks a lot,

Christophe

@gpleiss
Copy link
Owner

gpleiss commented Jul 26, 2017

The "size mismatch" error looks like its coming from the final classification layer. Did you set the num_classes option to be the correct number of classes?

@chmaz
Copy link
Author

chmaz commented Jul 29, 2017

Hi,

Yes, I have set the num_classes. I managed to have a training working with my images and resnet (adapting the resnet to the size of my images as described in pytorch/vision#155).
So my guess is that I get this error due to the custom size (80 x 80 pixels) of my images and I don't know how to adapt the densenet model for this image size.

I will keep looking,

Thanks,

Christophe

@gpleiss
Copy link
Owner

gpleiss commented Jul 29, 2017

My other guess is that its a pooling issue. The default settings (3 pooling blocks) will reduce a 32x32 image into 1x1 feature maps by the last layer. An 80x80 image might instead be reduced to 3x3 feature maps, which cannot directly be fed into the classifier without further pooling (or increasing the size of the layer).

@chmaz
Copy link
Author

chmaz commented Aug 3, 2017

By trying different values, I found that setting the avgpool_size to 10 solves the problem.

Thanks for the assistance,

Christophe

@chmaz chmaz closed this as completed Aug 3, 2017
@taineleau-zz
Copy link
Collaborator

taineleau-zz commented Aug 4, 2017

@chmaz Hi, I haven't seen this issue until now.

If you are going to test different size of images, I would recommend you using AdaptiveAvgPool2d or AdaptiveMaxPool2d instead of manually setting up the avgpooling size. I guess this would be much more convenient for you. :D

gpleiss pushed a commit that referenced this issue May 13, 2018
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