Cysu / open-reid

Open source person re-identification library in python
https://cysu.github.io/open-reid/
MIT License
1.34k stars 349 forks source link

error triplet_loss.py #18

Closed pribadihcr closed 7 years ago

pribadihcr commented 7 years ago

Hi @Cysu

I got triplet_loss error:

open-reid$ python examples/triplet_loss.py -d cuhk03 -b 64 -j 2 -a resnet50 --logs-dir logs/triplet-loss/cuhk03-resnet50 Files already downloaded and verified CUHK03 dataset loaded subset | # ids | # images train | 1267 | 24345 val | 100 | 1918 trainval | 1367 | 26263 query | 100 | 1930 gallery | 100 | 1930 Traceback (most recent call last): File "examples/triplet_loss.py", line 217, in main(parser.parse_args()) File "examples/triplet_loss.py", line 145, in main trainer.train(epoch, train_loader, optimizer) File "open-reid/reid/trainers.py", line 31, in train loss, prec1 = self._forward(inputs, targets) File "open-reid/reid/trainers.py", line 80, in _forward loss, prec = self.criterion(outputs, targets) File "/usr/local/lib/python2.7/dist-packages/torch/nn/modules/module.py", line 224, in call result = self.forward(*input, **kwargs) File "open-reid/reid/loss/triplet.py", line 26, in forward dist_an.append(dist[i][1 - mask[i]].min()) File "/usr/local/lib/python2.7/dist-packages/torch/autograd/variable.py", line 826, in rsub return SubConstant.apply(other, self) File "/usr/local/lib/python2.7/dist-packages/torch/autograd/_functions/basicops.py", line 130, in forward return tensor.neg().add(constant) AttributeError: 'torch.cuda.ByteTensor' object has no attribute 'neg'

Cysu commented 7 years ago

@pribadihcr What's the version of your pytorch?

Cysu commented 7 years ago

@pribadihcr Seems to be a bug in pytorch v0.2. A quick workaround is to change this line to

dist_an.append(dist[i][mask[i] == 0].min())
pribadihcr commented 7 years ago

HI @Cysu

yes, I am using v0.2. And also we need to change loss/triplet.py in line 26 with dist_an.append(dist[i][1 + (-1)*mask[i]].min()) to get triplet_loss.py working.