Open xwjabc opened 6 years ago
@xwjabc I met the same problem and I'm not familiar with pytorch. But change this line https://github.com/gidariss/FewShotWithoutForgetting/blob/master/algorithms/FewShot.py#L55 to self.nKbase = nKbase.squeeze()[0].cuda() fix the problem.
@caiqi Thx! Will take a look. I am also a newbie to PyTorch and trying to trace the reason of that error.
Got the reason. In PyTorch 0.4, x.squeeze()[0]
will not return a scalar, but a tensor. It will cause several compatibility problems (e.g. nKbase errors, DAverageMeter errors). Will post a patch list later.
@xwjabc I met possibly the same DAverageMeter error (AccuracyNovel is missing). Could you please tell me how to fix it?
@jin-s13 Could you add some more details for the error information?
@jin-s13 My suggestion; if you are still interested, is you should add .item() at the end of top1accuracy() function whenever you calculate Accuracies for Novel, Base or Both this will turn the loss_record into a scalar for the aforementioned accuracies
Here is my solution:
#labels_train = self.tensors['labels_train']
nKnovel = 1 + labels_train.max() - self.nKbase
labels_train_1hot_size = list(labels_train.size()) + [nKnovel,] labels_train_unsqueeze = labels_train.unsqueeze(dim=labels_train.dim()) self.tensors['labels_train1hot'].resize(labels_train_1hotsize).fill(0).scatter_( len(labels_train_1hot_size) - 1, (labels_train_unsqueeze - self.nKbase).cuda(), 1)
When executing the command below:
CUDA_VISIBLE_DEVICES=0 python train.py --config=miniImageNet_Conv128CosineClassifier
It prompts:
Environment: Python 2.7 PyTorch 0.4 @ CUDA 9.1