Giter Club home page Giter Club logo

Comments (2)

zydou avatar zydou commented on May 26, 2024 4

Hi @Linranran :
In the code we can see that:

if relabel:
ret.append((fname, index, camid))
else:
ret.append((fname, pid, camid))

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:

def _forward(self, inputs, targets):
outputs = self.model(*inputs)
if isinstance(self.criterion, torch.nn.CrossEntropyLoss):
loss = self.criterion(outputs, targets)

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:
model = models.create(args.arch, num_features=args.features,
dropout=args.dropout, num_classes=num_classes)

and used to create the model:
self.classifier = nn.Linear(self.num_features, self.num_classes)

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

from open-reid.

Cysu avatar Cysu commented on May 26, 2024

@zydou Thank you so much for your detailed explaination. I really appreciate it.

from open-reid.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.