Closed Linranran closed 6 years ago
Hi @Linranran :
In the code we can see that:
https://github.com/Cysu/open-reid/blob/5db4f6b4245b8b24073f19c161a3b869121a1d2c/reid/utils/data/dataset.py#L18-L21
relabel=True
makes the pids continuous from 0 to the total number of persons in the datasets(or subsets).
If you change relabel=True
to relabel=False
, the pids will be the real id according to the original datasets.
In the training progress at here:
https://github.com/Cysu/open-reid/blob/5db4f6b4245b8b24073f19c161a3b869121a1d2c/reid/trainers.py#L69-L72
the variable outputs
is a tensor which the size is B * C
and targets
is a tensor which the size is B
, where B
is minibatch size and C
is number of classes.
C
is defined at here:
https://github.com/Cysu/open-reid/blob/5db4f6b4245b8b24073f19c161a3b869121a1d2c/examples/softmax_loss.py#L89-L90
and used to create the model:
https://github.com/Cysu/open-reid/blob/5db4f6b4245b8b24073f19c161a3b869121a1d2c/reid/models/resnet.py#L58
Let's take Market1501 for example:
If relabel=True
:
outputs
is B * 751
, because the trainval dataset contains 751 persons. targets
is pids which ranges from 0 to 750.
If relabel=False
:
outputs
is B * 751
but targets
is ranging from 2 to 1500.( targets
is the real id according to the original datasets)
From the PyTorch official docs about CrossEntropyLoss
:
The input is expected to contain scores for each class.
input
has to be a 2D Tensor of size (minibatch, C). This criterion expects a class index (0 to C-1) as the target for each value of a 1D tensor of size minibatch
So it will raise an error when you use CrossEntropyLoss
because the targets
is exceeded index (0 to C-1).
More information: http://pytorch.org/docs/master/nn.html#torch.nn.CrossEntropyLoss
@zydou Thank you so much for your detailed explaination. I really appreciate it.
hi xiaotong: i change some place in the code in https://github.com/Cysu/open-reid/blob/master/reid/utils/data/dataset.py
self.meta = read_json(osp.join(self.root, 'meta.json')) identities = self.meta['identities'] self.train = _pluck(identities, train_pids, relabel=True) self.val = _pluck(identities, val_pids, relabel=True) self.trainval = _pluck(identities, trainval_pids, relabel=True) self.query = _pluck(identities, self.split['query']) self.gallery = _pluck(identities, self.split['gallery']) self.num_train_ids = len(train_pids) self.num_val_ids = len(val_pids) self.num_trainval_ids = len(trainval_pids)
i change the" relabel=True" to" relabel=False" and the errors occured when i run the code .dubug the code i find the paremeters show "unable to get repr for ..."when compute the loss at
def _forward(self, inputs, targets): outputs = self.model(*inputs) if isinstance(self.criterion, torch.nn.CrossEntropyLoss): loss = self.criterion(outputs, targets) prec, = accuracy(outputs.data, targets.data) prec = prec[0]
i didn't find why the error occur ,can you help @Cysu @wk910930 @zydou