vision: Failed in fine-tuning inception_v3
I failed in using inception_v3 on my own dataset. (Ubuntu14.04, cuda8.0, python3.6.2)
It outputs warning when loaded:
/home/ljy/anaconda3/lib/python3.6/site-packages/torchvision-0.1.9-py3.6.egg/torchvision/models/inception.py:65: UserWarning: src is not broadcastable to dst, but they have the same number of elements. Falling back to deprecated pointwise behavior.
It failed which training:
Traceback (most recent call last):
File "/home/ljy/pytorch-examples-master/cub_pytorch/main.py", line 382, in <module>
main()
File "/home/ljy/pytorch-examples-master/cub_pytorch/main.py", line 213, in main
train(train_loader, model, criterion, optimizer, epoch)
File "/home/ljy/pytorch-examples-master/cub_pytorch/main.py", line 251, in train
loss = criterion(output, target_var)
File "/home/ljy/anaconda3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 224, in __call__
result = self.forward(*input, **kwargs)
File "/home/ljy/anaconda3/lib/python3.6/site-packages/torch/nn/modules/loss.py", line 482, in forward
self.ignore_index)
File "/home/ljy/anaconda3/lib/python3.6/site-packages/torch/nn/functional.py", line 746, in cross_entropy
return nll_loss(log_softmax(input), target, weight, size_average, ignore_index)
File "/home/ljy/anaconda3/lib/python3.6/site-packages/torch/nn/functional.py", line 537, in log_softmax
return _functions.thnn.LogSoftmax.apply(input)
File "/home/ljy/anaconda3/lib/python3.6/site-packages/torch/nn/_functions/thnn/auto.py", line 126, in forward
ctx._backend = type2backend[type(input)]
File "/home/ljy/anaconda3/lib/python3.6/site-packages/torch/_thnn/__init__.py", line 15, in __getitem__
return self.backends[name].load()
KeyError: <class 'tuple'>
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 35 (14 by maintainers)
@jamiechoi1995 @MichaelLiang12, @TiRune is correct, inception_v3 has an aux branch, and if this is not disabled the forward function will return a tuple (see here), which when passed to the criterion will throw this error.
So you have two choices:
disable
aux_logits
when the model is created here by also passingaux_logits=False
to theinception_v3
function.edit your
train
function to accept and unpack the returned tuple here to be something like:@tejasri19 for inference, don’t forget to set your model to
eval()
mode.You don’t need to use the aux classifiers for inference, only for training
Yeah, thanks.
@rajasekharponakala one thing to note here is that GoogLeNet has two aux branches where as inception v3 only has one.
So for GoogLeNet you have to use:
aux1, aux2, output = model(inputs)
@alykhantejani:Hi, why we have to disable the
aux_logits
?, what are theseaux_logits
? does they effect the training/validation?I’m trying to reproduce the accuracy from a model trained using with the bvlc_googlenet (without pretrained weights). So when I do aux branch off with pytorch(googlenet) it works and reports val_acc with 50% which is very low when compared to the caffe. any other methods to reproduce the same accurcy using pytorch? Thanks.
Also the user warning you are getting when loading the model is fixed in master (via #231)