Error loading market1501 osnet_x1_0 weights under Same-domain ReID in model zoo

See original GitHub issue

Hi!

I am trying to load the pretrained market1501 osnet_x1_0 weights under https://kaiyangzhou.github.io/deep-person-reid/MODEL_ZOO.html#same-domain-reid by:


datamanager = torchreid.data.ImageDataManager(
    root='reid-data',
    sources='market1501',
    targets='market1501',
    height=256,
    width=128,
    batch_size_train=32,
    batch_size_test=100,
    transforms=['random_flip', 'random_crop']
)
model = models.build_model(name='osnet_x1_0', num_classes=datamanager.num_train_pids)
torchreid.utils.load_pretrained_weights(model, weight_path='/x/osnet_x1_0_market_256x128_amsgrad_ep150_stp60_lr0.0015_b64_fb10_softmax_labelsmooth_flip.pth')

but I get:

** The following layers are discarded due to unmatched keys or layer size: ['classifier.weight', 'classifier.bias']

The weights name has market in it so I supposed it was trained on 1501 classes but this is not the case. Anybody knows that the problem is here?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
mikel-brostromcommented, Jan 4, 2022

you are ignoring the final classification layer, instead you take the 512-d embedding vector for matching with the gallery

You are totally right there @sholevs66.

Then I guess it would be better to use the FeatureExtractor right away:

extractor = FeatureExtractor(
    model_name='osnet_x1_0',
    model_path='a/b/c/model.pth.tar',
    device='cuda'
)

image_list = [
    'a/b/c/image001.jpg',
    'a/b/c/image002.jpg',
    'a/b/c/image003.jpg',
    'a/b/c/image004.jpg',
    'a/b/c/image005.jpg'
]

features = extractor(image_list)
print(features.shape) # output (5, 512)

instead of

model = models.build_model(name='osnet_x1_0', num_classes=datamanager.num_train_pids)
1reaction
sholevs66commented, Jan 3, 2022

Can you please tell me where did you find osnet_x1_0_market_256x128_amsgrad_ep150_stp60_lr0.0015_b64_fb10_softmax_labelsmooth_flip ?

Click on 94.2 (82.6) under https://kaiyangzhou.github.io/deep-person-reid/MODEL_ZOO.html#same-domain-reid

Is this supposed to be a osnet model pretrained on ImageNet followd by training on market1501 train?

In the OSNet paper they state: For fair comparison against existing methods, we implement two versions of OSNet. One is trained from scratch while the other is fine-tuned from ImageNet pre-trained weights.. Neither the mAP score nor the R1 score under https://kaiyangzhou.github.io/deep-person-reid/MODEL_ZOO.html#same-domain-reid corresponds to any of the two model results in the paper, so it is hard to tell.

I just assumed that this is because this .pth doesn’t contain the last classifying re-id layer. am I correct?

The key for the last layer is classifier.bias as in

** The following layers are discarded due to unmatched keys or layer size: ['classifier.weight', 'classifier.bias']

so it must have a classifying ReID layer, but its size is 751 for some reason

Well, there are 751 identities for train and 750 for test. So, it fits. Eitherway, if you are using a trained model for eval on the test set, you are ignoring the final classification layer, instead you take the 512-d embedding vector for matching with the gallery. You can verify it by running: datamanager.num_train_pids for the market1501 data manager youv’e created. image

Yea, I see the mismatch you talk about between the paper performance and the provided models in the git. I have started training the ImageNet pretrained model on the market1501 and I still haven’t passed the 91% CMC1, while the paper has >93 for either model (pre train ImageNet + market train, or fully market train from scratch). Still playing with it.

hope this helps

Read more comments on GitHub >

github_iconTop Results From Across the Web

Need to download datasets ? #111 - GitHub
Have a simple question on how to use the pretrained versions on a given dataset or my own one. I got the weights...
Read more >
torchreid 1.4.0 documentation - Kaiyang Zhou
Torchreid is a library for deep-learning person re-identification, written in PyTorch and developed for our ICCV'19 project, Omni-Scale Feature Learning for ...
Read more >
Model Zoo - Deep learning code and pretrained models for ...
ModelZoo curates and provides a platform for deep learning researchers to easily find code and pre-trained models for a variety of platforms and...
Read more >
FiftyOne Model Zoo - Voxel51
FiftyOne provides a Model Zoo that contains a collection of pre-trained models that you can download and run inference on your FiftyOne Datasets...
Read more >
Market-1501 Benchmark (Person Re-Identification)
Rank Model mAP Rank‑1 Rank‑5 Rank‑10 Year 1 CTL Model (ResNet‑50, 256x128) 98.3 98.0 98.6 99.5 2021 2 Unsupervised Pre‑training (ResNet101+RK) 96.21 2020 3 RGT&RGPR (RK)...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found