Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mahalanobis distance calculation matrix is not working and throwing these errors #11

Open
harshnandwana opened this issue Jan 5, 2024 · 1 comment

Comments

@harshnandwana
Copy link
Contributor

python src/demo.py --img_path 1000_F_26800115_YlmErNLIVZeNZXPzUc3z4GAD1gGkVABu.jpg --cfg /app/mmpretrain/work_dirs/beitv2_beit-base-p16_8xb256-amp-coslr-300e_in1k/beitv2_beit-base-p16_8xb256-amp-coslr-300e_in1k.py --checkpoint pretrain/epoch_19.pth --fc outputs/fc.pkl --id_train_feature outputs/imagenet_train.pkl --id_val_feature outputs/imagenet_train.pkl --methods Mahalanobis
=> Loading model
/root/miniconda3/envs/open-mmlab/lib/python3.8/site-packages/torch/functional.py:445: UserWarning: torch.meshgrid: in an upcoming release, it will be required to pass the indexing argument. (Triggered internally at /opt/conda/conda-bld/pytorch_1639180588308/work/aten/src/ATen/native/TensorShape.cpp:2157.)
return _VF.meshgrid(tensors, **kwargs) # type: ignore[attr-defined]
Loads checkpoint by local backend from path: pretrain/epoch_19.pth
=> Loading image
=> Extracting feature
Extracted Feature: (1, 768)
w.shape=(8192, 768), b.shape=(8192,)
image path: 1000_F_26800115_YlmErNLIVZeNZXPzUc3z4GAD1gGkVABu.jpg
=> Loading features
feature_id_train.shape=(91710, 768), feature_id_val.shape=(91710, 768)
=> Computing logits...
=> Computing softmax...
Computing classwise mean feature: 0%| | 0/1000 [00:00<?, ?it/s]
Traceback (most recent call last):
File "src/demo.py", line 305, in
main()
File "src/demo.py", line 263, in main
fs = feature_id_train[train_labels == i]
IndexError: boolean index did not match indexed array along dimension 0; dimension is 91710 but corresponding boolean dimension is 200000

@JulietLJY
Copy link
Member

This is due to a mismatch in shapes between your image_train.pkl and the Image_list. This may be because your ImageNet dataset is incomplete, resulting in a dimension of 91710 instead of 200k. To use Mahalanobis, you can choose to:

  1. Use our preprocessed image_train.pkl, which matches our provided datalists/imagenet2012_train_random_200k.txt.
  2. Use your custom Image_list, which needs to match the Image_train.pkl you are using.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants