bioclip icon indicating copy to clipboard operation
bioclip copied to clipboard

RuntimeError: selected index k out of range

Open Lagunaxx opened this issue 2 years ago • 3 comments

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?

Lagunaxx avatar Dec 20 '23 07:12 Lagunaxx

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.

samuelstevens avatar Dec 21 '23 00:12 samuelstevens

May I ask how many classes you use and how many images you use?

work4cs avatar Dec 21 '23 01:12 work4cs

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.

samuelstevens avatar Dec 21 '23 01:12 samuelstevens