RuntimeError: selected index k out of range
hi, playin with example zero_shot.py and got error RuntimeError: selected index k out of range (line 174). what can be metter of this? how to avoid error?
Hi! Can you provide the exact command you used? And a description of the dataset and its structure on the disk? When I run the command below, I don't get any errors.
python examples/zero_shot.py --datasets insects2=data/examples/val/
data/examples/val has the following structure:
val
├── Apple leaf
│ ├── 10124.jpg
│ ├── ...
│ └── 9881.jpg
├── Apple rust leaf
│ ├── 10292.jpg
│ ├── ...
│ └── 1320.jpg
├── ...
The zero-shot classnames are the folder names.
If you provide more details, I'm happy to help.
May I ask how many classes you use and how many images you use?
My co-author suggests that if you have less than five classes, top5 accuracy is meaningless. In this case, you can remove all references to top5 accuracy (lines 193, 210, 214) and only calculate top1 accuracy. Line 208 should be changed:
acc1, acc5 = accuracy(logits, targets, topk=(1, 5))
to
acc1 = accuracy(logits, targets, topk=(1,))[0]
If you have zero classes, then this script will not work at all.