Instructions to use kritaphatson/thai_snake_image_classifier with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- timm
How to use kritaphatson/thai_snake_image_classifier with timm:
import timm model = timm.create_model("hf-hub:kritaphatson/thai_snake_image_classifier", pretrained=True) - Notebooks
- Google Colab
- Kaggle
Add frozen image embeddings (BioCLIP 2, DINOv2, CLIP ViT-L/14) of all benchmark images
Browse files- benchmark_v4/embeddings/README.md +70 -0
- benchmark_v4/embeddings/bioclip2_vitl14.npy +3 -0
- benchmark_v4/embeddings/bioclip2_zero_shot_class_texts.csv +140 -0
- benchmark_v4/embeddings/bioclip2_zero_shot_text_weights.npy +3 -0
- benchmark_v4/embeddings/checksums.json +11 -0
- benchmark_v4/embeddings/classes.json +141 -0
- benchmark_v4/embeddings/clip_vitl14_laion2b.npy +3 -0
- benchmark_v4/embeddings/dinov2_vitb14_reg4.npy +3 -0
- benchmark_v4/embeddings/example_probe.py +71 -0
- benchmark_v4/embeddings/index.csv +0 -0
benchmark_v4/embeddings/README.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Thai snake identification benchmark: frozen image embeddings
|
| 2 |
+
|
| 3 |
+
Frozen image embeddings for all 26,368 images of the Thai snake identification benchmark: 139 species,
|
| 4 |
+
photographs and video frames from citizen-science reports, and a development/test split grouped by report, post and
|
| 5 |
+
duplicate. Each file holds one 768-dimensional vector per image, from a pretrained model that never saw the
|
| 6 |
+
benchmark during training. With them, anyone can train and score classifiers on the exact split, cross-validation
|
| 7 |
+
folds and locked test set, for example probes, long-tail methods, venom alerts, open-set rejection or fusion. The
|
| 8 |
+
photographs themselves are not released (see *Copyright and privacy*).
|
| 9 |
+
|
| 10 |
+
The records, predictions and code are at <https://github.com/kritsong/thai_snake_classification> (folder
|
| 11 |
+
`benchmark/`); the trained checkpoints are in `benchmark_v4/` of this repository.
|
| 12 |
+
|
| 13 |
+
## Files
|
| 14 |
+
|
| 15 |
+
| File | Contents |
|
| 16 |
+
|---|---|
|
| 17 |
+
| `bioclip2_vitl14.npy` | BioCLIP 2 (ViT-L/14, `imageomics/bioclip-2`, OpenCLIP 3.3.0): L2-normalized projected image embedding |
|
| 18 |
+
| `dinov2_vitb14_reg4.npy` | DINOv2 ViT-B/14 with registers (`timm` `vit_base_patch14_reg4_dinov2.lvd142m`): CLS token, not normalized |
|
| 19 |
+
| `clip_vitl14_laion2b.npy` | CLIP ViT-L/14 trained on LAION-2B (OpenCLIP `laion2b_s32b_b82k`), the model BioCLIP 2 was initialized from: L2-normalized image embedding |
|
| 20 |
+
| `index.csv` | Row *i* of every `.npy` file: image path, SHA-256 of the source file, `split` (`development`/`test`), `cv_fold` (1-5, or `test`), species, `label_id`, source type (still or video frame), and keyed record, group and video identifiers |
|
| 21 |
+
| `classes.json` | The 139 species in `label_id` order |
|
| 22 |
+
| `bioclip2_zero_shot_text_weights.npy`, `bioclip2_zero_shot_class_texts.csv` | BioCLIP 2 text classifier (139 x 768) and the taxonomic texts it was built from |
|
| 23 |
+
| `example_probe.py` | Trains the paper's logistic-regression probe and scores the test set or the CV folds; also runs zero-shot |
|
| 24 |
+
| `checksums.json` | SHA-256 of every file |
|
| 25 |
+
|
| 26 |
+
All arrays are float32, shape 26,368 x 768, in the row order of `index.csv`. Embeddings were computed with float16
|
| 27 |
+
autocast from the benchmark's stored copies (shorter side 448 pixels, JPEG quality 95). BioCLIP 2 and CLIP:
|
| 28 |
+
bicubic resize of the shorter side to 224, centre crop 224, CLIP normalization. DINOv2: bicubic resize of the
|
| 29 |
+
shorter side to 256, centre crop 224, ImageNet normalization. No flip averaging.
|
| 30 |
+
|
| 31 |
+
## Use
|
| 32 |
+
|
| 33 |
+
```bash
|
| 34 |
+
python example_probe.py bioclip2_vitl14.npy # test accuracy 0.625 (paper 0.624)
|
| 35 |
+
python example_probe.py dinov2_vitb14_reg4.npy # 0.518 (paper 0.518)
|
| 36 |
+
python example_probe.py clip_vitl14_laion2b.npy # 0.362 (paper 0.360)
|
| 37 |
+
python example_probe.py bioclip2_vitl14.npy --zero-shot # 0.443 (paper 0.443)
|
| 38 |
+
python example_probe.py bioclip2_vitl14.npy --cv # five grouped CV folds
|
| 39 |
+
```
|
| 40 |
+
|
| 41 |
+
The probe stops at a solver tolerance, so its result shifts by about 0.1 point with the order of the
|
| 42 |
+
training rows; the zero-shot result is exact.
|
| 43 |
+
|
| 44 |
+
Rules of the benchmark: choose every setting on the development images (the CV folds keep reports, posts and
|
| 45 |
+
duplicates together), and score the test set once. Report results for all 106 species that have test images,
|
| 46 |
+
overall and by the number of development images per species. For uncertainty, resample test groups
|
| 47 |
+
(`group_key`), not images.
|
| 48 |
+
|
| 49 |
+
## Copyright and privacy
|
| 50 |
+
|
| 51 |
+
The photographs and videos were posted publicly by members of the public, and public posting does not grant
|
| 52 |
+
permission to republish them, so they are not released. These files contain only derived numerical features: one
|
| 53 |
+
pooled vector per image, from which the photograph cannot be recovered. No patch-level features, images,
|
| 54 |
+
thumbnails, URLs, post or poster fields, or locations are included. Record, group and video identifiers are keyed
|
| 55 |
+
hashes that cannot be traced back to the source records.
|
| 56 |
+
|
| 57 |
+
If you took one of these photographs and want its features removed, open a discussion on this repository or
|
| 58 |
+
contact the corresponding authors of the paper, and we will remove the record.
|
| 59 |
+
|
| 60 |
+
## Licence
|
| 61 |
+
|
| 62 |
+
The embeddings, index and texts are released under
|
| 63 |
+
[CC BY-NC 4.0](https://creativecommons.org/licenses/by-nc/4.0/) for non-commercial research and teaching. The
|
| 64 |
+
example script is under the MIT licence. The pretrained models that produced the embeddings carry their own
|
| 65 |
+
licences; see their model cards.
|
| 66 |
+
|
| 67 |
+
## Citation
|
| 68 |
+
|
| 69 |
+
Songsri-in, K., Chiu, C.-Y., Rattaphun, M. and Ratnarathorn, N. Deep Learning and Citizen Science for Automated
|
| 70 |
+
Snake Species Identification in Thailand: A Regional Benchmark (manuscript under review).
|
benchmark_v4/embeddings/bioclip2_vitl14.npy
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:3b6abc61ed323e3b359a04a731ce0381633796879aee0108b0af32516a6e6285
|
| 3 |
+
size 81002624
|
benchmark_v4/embeddings/bioclip2_zero_shot_class_texts.csv
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
class_label,text,source
|
| 2 |
+
Acrochordus granulatus,Animalia Chordata Squamata Acrochordidae Acrochordus granulatus with common name Little filesnake,treeoflife
|
| 3 |
+
Acrochordus javanicus,Animalia Chordata Squamata Acrochordidae Acrochordus javanicus with common name Elephant trunk snake,treeoflife
|
| 4 |
+
Ahaetulla fasciolata,Animalia Chordata Squamata Colubridae Ahaetulla fasciolata with common name Speckled-headed whip snake,treeoflife
|
| 5 |
+
Ahaetulla nasuta,Animalia Chordata Squamata Colubridae Ahaetulla nasuta with common name Green vine snake,treeoflife
|
| 6 |
+
Ahaetulla prasina,Animalia Chordata Squamata Colubridae Ahaetulla prasina with common name Oriental whip snake,treeoflife
|
| 7 |
+
Amphiesma stolatum,Animalia Chordata Squamata Colubridae Amphiesma stolatum with common name Buff striped keelback,treeoflife
|
| 8 |
+
Aplopeltura boa,Animalia Chordata Squamata Pareidae Aplopeltura boa with common name Blunthead slug snake,treeoflife
|
| 9 |
+
Argyrophis diardii,Animalia Chordata Squamata Typhlopidae Argyrophis diardii with common name Diard's blindsnake,treeoflife
|
| 10 |
+
Argyrophis muelleri,Animalia Chordata Squamata Typhlopidae Argyrophis muelleri with common name Müller's blind snake,treeoflife
|
| 11 |
+
Asthenodipsas malaccana,Animalia Chordata Squamata Pareidae Asthenodipsas malaccanus with common name Malayan slug snake,treeoflife_synonym
|
| 12 |
+
Boiga bengkuluensis,Animalia Chordata Squamata Colubridae Boiga bengkuluensis with common name Bengkulu cat snake,treeoflife
|
| 13 |
+
Boiga cyanea,Animalia Chordata Squamata Colubridae Boiga cyanea with common name Green cat snake,treeoflife
|
| 14 |
+
Boiga cynodon,Animalia Chordata Squamata Colubridae Boiga cynodon with common name Dog-toothed cat snake,treeoflife
|
| 15 |
+
Boiga drapiezii,Animalia Chordata Squamata Colubridae Boiga drapiezii with common name White-spotted cat snake,treeoflife
|
| 16 |
+
Boiga melanota,Animalia Chordata Squamata Colubridae Boiga melanota,treeoflife
|
| 17 |
+
Boiga multomaculata,Animalia Chordata Squamata Colubridae Boiga multomaculata with common name Many-spotted cat snake,treeoflife
|
| 18 |
+
Boiga nigriceps,Animalia Chordata Squamata Colubridae Boiga nigriceps with common name Black-headed cat snake,treeoflife
|
| 19 |
+
Boiga siamensis,Animalia Chordata Squamata Colubridae Boiga siamensis with common name Eyed cat snake,treeoflife
|
| 20 |
+
Bungarus fasciatus,Animalia Chordata Squamata Elapidae Bungarus fasciatus with common name Banded krait,treeoflife
|
| 21 |
+
Bungarus flaviceps,Animalia Chordata Squamata Elapidae Bungarus flaviceps with common name Red-headed krait,treeoflife
|
| 22 |
+
Bungarus wanghaotingi,Animalia Chordata Squamata Elapidae Bungarus multicinctus with common name Many-banded krait,treeoflife_synonym
|
| 23 |
+
Calamaria lumbricoidea,Animalia Chordata Squamata Colubridae Calamaria lumbricoidea with common name Variable reed snake,treeoflife
|
| 24 |
+
Calamaria pavimentata,Animalia Chordata Squamata Colubridae Calamaria pavimentata with common name Collared reed snake,treeoflife
|
| 25 |
+
Calliophis bivirgatus,Animalia Chordata Squamata Elapidae Calliophis bivirgatus,treeoflife
|
| 26 |
+
Calliophis gracilis,Animalia Chordata Squamata Elapidae Calliophis gracilis with common name Spotted coral snake,treeoflife
|
| 27 |
+
Calliophis intestinalis,Animalia Chordata Squamata Elapidae Calliophis intestinalis with common name Striped coral snake,treeoflife
|
| 28 |
+
Calliophis maculiceps,Animalia Chordata Squamata Elapidae Calliophis maculiceps with common name Speckled coral snake,treeoflife
|
| 29 |
+
Calloselasma rhodostoma,Animalia Chordata Squamata Viperidae Calloselasma rhodostoma with common name Malayan pit viper,treeoflife
|
| 30 |
+
Cantoria violacea,Animalia Chordata Squamata Homalopsidae Cantoria violacea with common name Cantor's water snake,treeoflife
|
| 31 |
+
Cerberus schneiderii,Animalia Chordata Squamata Homalopsidae Cerberus schneiderii with common name Southeast asian bockadam,treeoflife
|
| 32 |
+
Chrysopelea ornata,Animalia Chordata Squamata Colubridae Chrysopelea ornata with common name Ornate Flying Snake,treeoflife
|
| 33 |
+
Chrysopelea paradisi,Animalia Chordata Squamata Colubridae Chrysopelea paradisi with common name Paradise tree snake,treeoflife
|
| 34 |
+
Chrysopelea pelias,Animalia Chordata Squamata Colubridae Chrysopelea pelias with common name Twin-barred tree snake,treeoflife
|
| 35 |
+
Coelognathus flavolineatus,Animalia Chordata Squamata Colubridae Coelognathus flavolineatus with common name Black copper rat snake,treeoflife
|
| 36 |
+
Coelognathus radiatus,Animalia Chordata Squamata Colubridae Coelognathus radiatus with common name Copperhead rat snake,treeoflife
|
| 37 |
+
Cylindrophis jodiae,Animalia Chordata Squamata Cylindrophiidae Cylindrophis jodiae with common name Jodi’s pipe-snake,treeoflife
|
| 38 |
+
Daboia siamensis,Animalia Chordata Squamata Viperidae Daboia siamensis with common name Eastern russell's viper,treeoflife
|
| 39 |
+
Dendrelaphis caudolineatus,Animalia Chordata Squamata Colubridae Dendrelaphis caudolineatus with common name Striped bronzeback,treeoflife
|
| 40 |
+
Dendrelaphis cyanochloris,Animalia Chordata Squamata Colubridae Dendrelaphis cyanochloris with common name Wall's bronzeback,treeoflife
|
| 41 |
+
Dendrelaphis formosus,Animalia Chordata Squamata Colubridae Dendrelaphis formosus with common name Elegant bronzeback,treeoflife
|
| 42 |
+
Dendrelaphis haasi,Animalia Chordata Squamata Colubridae Dendrelaphis haasi with common name Haas�s bronzeback,treeoflife
|
| 43 |
+
Dendrelaphis kopsteini,Animalia Chordata Squamata Colubridae Dendrelaphis kopsteini with common name Kopstein�s bronzeback,treeoflife
|
| 44 |
+
Dendrelaphis nigroserratus,Animalia Chordata Squamata Colubridae Dendrelaphis nigroserratus with common name Sawtooth-necked bronzeback,treeoflife
|
| 45 |
+
Dendrelaphis pictus,Animalia Chordata Squamata Colubridae Dendrelaphis pictus with common name Indonesian bronze-back,treeoflife
|
| 46 |
+
Dendrelaphis striatus,Animalia Chordata Squamata Colubridae Dendrelaphis striatus with common name Cohn�s bronzeback,treeoflife
|
| 47 |
+
Dendrelaphis subocularis,Animalia Chordata Squamata Colubridae Dendrelaphis subocularis with common name Mountain bronzeback tree snake,treeoflife
|
| 48 |
+
Dendrelaphis vogeli,Animalia Chordata Squamata Colubridae Dendrelaphis vogeli with common name Vogel’s bronzeback,treeoflife
|
| 49 |
+
Dryophiops rubescens,Animalia Chordata Squamata Colubridae Dryophiops rubescens with common name Red whip snake,treeoflife
|
| 50 |
+
Elaphe taeniura,Animalia Chordata Squamata Colubridae Elaphe taeniura with common name Beauty snake,treeoflife
|
| 51 |
+
Enhydris chanardi,Animalia Chordata Squamata Homalopsidae Enhydris chanardi with common name Sind river snake,treeoflife
|
| 52 |
+
Enhydris enhydris,Animalia Chordata Squamata Homalopsidae Enhydris enhydris with common name Rainbow water snake,treeoflife
|
| 53 |
+
Enhydris subtaeniata,Animalia Chordata Squamata Homalopsidae Enhydris subtaeniata with common name Mekong mud snake,treeoflife
|
| 54 |
+
Erpeton tentaculatum,Animalia Chordata Squamata Homalopsidae Erpeton tentaculatum with common name Tentacle snake,treeoflife
|
| 55 |
+
Fowlea flavipunctatus,Animalia Chordata Squamata Colubridae Fowlea flavipunctatus with common name Yellow-spotted keelback,treeoflife
|
| 56 |
+
Fowlea piscator,Animalia Chordata Squamata Colubridae Fowlea piscator with common name Asiatic water snake,treeoflife
|
| 57 |
+
Gongylosoma scriptum,Animalia Chordata Squamata Colubridae Gongylosoma scriptum with common name Common ringneck,treeoflife
|
| 58 |
+
Gonyosoma oxycephalum,Animalia Chordata Squamata Colubridae Gonyosoma oxycephalum with common name Red-tailed racer,treeoflife
|
| 59 |
+
Hebius deschauenseei,Animalia Chordata Squamata Colubridae Hebius deschauenseei with common name Deschaunsee's keelback,treeoflife
|
| 60 |
+
Hebius khasiensis,Animalia Chordata Squamata Colubridae Hebius khasiensis with common name Khasi hills keelback,treeoflife
|
| 61 |
+
Homalopsis buccata,Animalia Chordata Squamata Homalopsidae Homalopsis buccata with common name Masked water snake,treeoflife
|
| 62 |
+
Homalopsis mereljcoxi,Animalia Chordata Squamata Homalopsidae Homalopsis mereljcoxi with common name Jack’s water snake,treeoflife
|
| 63 |
+
Homalopsis nigroventralis,Animalia Chordata Squamata Homalopsidae Homalopsis nigroventralis with common name Deuve's water snake,treeoflife
|
| 64 |
+
Hydrophis curtus,Animalia Chordata Squamata Elapidae Hydrophis curtus with common name Shaw's sea snake,treeoflife
|
| 65 |
+
Hydrophis cyanocinctus,Animalia Chordata Squamata Elapidae Hydrophis cyanocinctus with common name Annulated sea snake,treeoflife
|
| 66 |
+
Hydrophis platurus,Animalia Chordata Squamata Elapidae Hydrophis platurus with common name Pelagic sea snake,treeoflife
|
| 67 |
+
Hypsiscopus plumbea,Animalia Chordata Squamata Homalopsidae Hypsiscopus plumbea with common name Rice paddy snake,treeoflife
|
| 68 |
+
Indotyphlops braminus,Animalia Chordata Squamata Typhlopidae Indotyphlops braminus with common name Brahminy blindsnake,treeoflife
|
| 69 |
+
Indotyphlops porrectus,Animalia Chordata Squamata Typhlopidae Indotyphlops porrectus with common name Slender worm snake,treeoflife
|
| 70 |
+
Laticauda colubrina,Animalia Chordata Squamata Elapidae Laticauda colubrina with common name Yellow-lipped sea krait,treeoflife
|
| 71 |
+
Laticauda laticaudata,Animalia Chordata Squamata Elapidae Laticauda laticaudata with common name Blue-banded sea krait,treeoflife
|
| 72 |
+
Lycodon capucinus,Animalia Chordata Squamata Colubridae Lycodon capucinus with common name Common wold snake/house snake,treeoflife
|
| 73 |
+
Lycodon cardamomensis,Animalia Chordata Squamata Colubridae Lycodon cardamomensis,congener_ranks
|
| 74 |
+
Lycodon davisonii,Animalia Chordata Squamata Colubridae Lycodon davisonii with common name Blanford's bridal snake,treeoflife
|
| 75 |
+
Lycodon effraenis,Animalia Chordata Squamata Colubridae Lycodon effraenis with common name Brown wolf snake,treeoflife
|
| 76 |
+
Lycodon fasciatus,Animalia Chordata Squamata Colubridae Lycodon fasciatus with common name Banded wolf snake,treeoflife
|
| 77 |
+
Lycodon laoensis,Animalia Chordata Squamata Colubridae Lycodon laoensis with common name Laotian wolf snake,treeoflife
|
| 78 |
+
Lycodon ophiophagus,Animalia Chordata Squamata Colubridae Lycodon ophiophagus with common name Snake-eater wolf snake,treeoflife
|
| 79 |
+
Lycodon septentrionalis,Animalia Chordata Squamata Colubridae Lycodon septentrionalis with common name Northern large-toothed snake,treeoflife
|
| 80 |
+
Lycodon subannulatus,Animalia Chordata Squamata Colubridae Lycodon subannulatus with common name Malayan bridal snake,treeoflife
|
| 81 |
+
Lycodon subcinctus,Animalia Chordata Squamata Colubridae Lycodon subcinctus with common name Malayan banded wolf snake,treeoflife
|
| 82 |
+
Malayopython reticulatus,Animalia Chordata Squamata Pythonidae Malayopython reticulatus with common name Reticulated python,treeoflife
|
| 83 |
+
Naja kaouthia,Animalia Chordata Squamata Elapidae Naja kaouthia with common name Monocled cobra,treeoflife
|
| 84 |
+
Naja siamensis,Animalia Chordata Squamata Elapidae Naja siamensis with common name Indo-chinese spitting cobra,treeoflife
|
| 85 |
+
Naja sumatrana,Animalia Chordata Squamata Elapidae Naja sumatrana with common name Equatorial spitting cobra,treeoflife
|
| 86 |
+
Oligodon barroni,Animalia Chordata Squamata Colubridae Oligodon barroni with common name Barron's kukri snake,treeoflife
|
| 87 |
+
Oligodon cinereus,Animalia Chordata Squamata Colubridae Oligodon cinereus with common name Ashy kukri snake,treeoflife
|
| 88 |
+
Oligodon cyclurus,Animalia Chordata Squamata Colubridae Oligodon cyclurus with common name Cantor's kukri snake,treeoflife
|
| 89 |
+
Oligodon deuvei,Animalia Chordata Squamata Colubridae Oligodon deuvei,treeoflife
|
| 90 |
+
Oligodon fasciolatus,Animalia Chordata Squamata Colubridae Oligodon fasciolatus with common name Fasciolated kukri snake,treeoflife
|
| 91 |
+
Oligodon mouhoti,Animalia Chordata Squamata Colubridae Oligodon mouhoti with common name Cambodian kukri snake,treeoflife
|
| 92 |
+
Oligodon phangan,Animalia Chordata Squamata Colubridae Oligodon phangan with common name Pha-ngan kukri snake,treeoflife
|
| 93 |
+
Oligodon purpurascens,Animalia Chordata Squamata Colubridae Oligodon purpurascens with common name Brown kukri snake,treeoflife
|
| 94 |
+
Oligodon signatus,Animalia Chordata Squamata Colubridae Oligodon signatus with common name Barred kukri snake,treeoflife
|
| 95 |
+
Oligodon taeniatus,Animalia Chordata Squamata Colubridae Oligodon taeniatus with common name Striped kukri snake,treeoflife
|
| 96 |
+
Ophiophagus hannah,Animalia Chordata Squamata Elapidae Ophiophagus hannah with common name Hamadryad,treeoflife
|
| 97 |
+
Oreocryptophis porphyraceus,Animalia Chordata Squamata Colubridae Oreocryptophis porphyraceus with common name Black-banded trinket snake,treeoflife
|
| 98 |
+
Ovophis monticola,Animalia Chordata Squamata Viperidae Ovophis monticola with common name Mountain pit viper,treeoflife
|
| 99 |
+
Pareas berdmorei,Animalia Chordata Squamata Pareidae Pareas berdmorei,congener_ranks
|
| 100 |
+
Pareas carinatus,Animalia Chordata Squamata Pareidae Pareas carinatus,treeoflife
|
| 101 |
+
Pareas hamptoni,Animalia Chordata Squamata Pareidae Pareas hamptoni with common name Hampton's slug snake,treeoflife
|
| 102 |
+
Pareas macularius,Animalia Chordata Squamata Pareidae Pareas macularius with common name Spotted slug snake,treeoflife
|
| 103 |
+
Pareas margaritophorus,Animalia Chordata Squamata Pareidae Pareas margaritophorus with common name Mountain slug snake,treeoflife
|
| 104 |
+
Plagiopholis nuchalis,Animalia Chordata Squamata Colubridae Plagiopholis nuchalis with common name Assam mountain snake,treeoflife
|
| 105 |
+
Psammodynastes pulverulentus,Animalia Chordata Squamata Pseudaspididae Psammodynastes pulverulentus with common name Common mock viper,treeoflife
|
| 106 |
+
Psammophis indochinensis,Animalia Chordata Squamata Psammophiidae Psammophis indochinensis with common name Indo-chinese sand snake,treeoflife
|
| 107 |
+
Pseudorabdion longiceps,Animalia Chordata Squamata Colubridae Pseudorabdion longiceps with common name Dwarf reed snake,treeoflife
|
| 108 |
+
Pseudoxenodon macrops,Animalia Chordata Squamata Colubridae Pseudoxenodon macrops with common name Big-eyed mountain keelback,treeoflife
|
| 109 |
+
Ptyas carinata,Animalia Chordata Squamata Colubridae Ptyas carinata with common name Keeled rat snake,treeoflife
|
| 110 |
+
Ptyas fusca,Animalia Chordata Squamata Colubridae Ptyas fusca with common name White-bellied rat snake,treeoflife
|
| 111 |
+
Ptyas korros,Animalia Chordata Squamata Colubridae Ptyas korros with common name Indo-chinese rat snake,treeoflife
|
| 112 |
+
Ptyas mucosa,Animalia Chordata Squamata Colubridae Ptyas mucosa with common name Oriental ratsnake,treeoflife
|
| 113 |
+
Python bivittatus,Animalia Chordata Squamata Pythonidae Python bivittatus with common name Burmese Python,treeoflife
|
| 114 |
+
Python brongersmai,Animalia Chordata Squamata Pythonidae Python brongersmai with common name Blood python,treeoflife
|
| 115 |
+
Rhabdophis chrysargos,Animalia Chordata Squamata Colubridae Rhabdophis chrysargos with common name Specklebelly keelback,treeoflife
|
| 116 |
+
Rhabdophis nigrocinctus,Animalia Chordata Squamata Colubridae Rhabdophis nigrocinctus with common name Green keelback,treeoflife
|
| 117 |
+
Rhabdophis subminiatus,Animalia Chordata Squamata Colubridae Rhabdophis subminiatus with common name Red-necked keelback,treeoflife
|
| 118 |
+
Sibynophis collaris,Animalia Chordata Squamata Colubridae Sibynophis collaris with common name Common many-tooth snake,treeoflife
|
| 119 |
+
Sibynophis melanocephalus,Animalia Chordata Squamata Colubridae Sibynophis melanocephalus with common name Black-headed collared snake,treeoflife
|
| 120 |
+
Sibynophis triangularis,Animalia Chordata Squamata Colubridae Sibynophis triangularis with common name Triangled black-headed snake,treeoflife
|
| 121 |
+
Sinomicrurus macclellandi,Animalia Chordata Squamata Elapidae Sinomicrurus macclellandi with common name Maclelland's coral snake,treeoflife
|
| 122 |
+
Subsessor bocourti,Animalia Chordata Squamata Homalopsidae Subsessor bocourti with common name Bocourt's water snake,treeoflife
|
| 123 |
+
Trimeresurus albolabris,Animalia Chordata Squamata Viperidae Trimeresurus albolabris with common name White-lipped pitviper,treeoflife
|
| 124 |
+
Trimeresurus cardamomensis,Animalia Chordata Squamata Viperidae Trimeresurus cardamomensis with common name Cardamom mountains green pitviper,treeoflife
|
| 125 |
+
Trimeresurus gumprechti,Animalia Chordata Squamata Viperidae Trimeresurus gumprechti with common name Gumprecht's pit viper,treeoflife
|
| 126 |
+
Trimeresurus guoi,Animalia Chordata Squamata Viperidae Trimeresurus guoi with common name Guo’s green pit viper,treeoflife
|
| 127 |
+
Trimeresurus hageni,Animalia Chordata Squamata Viperidae Trimeresurus hageni with common name Indonesian pit viper,treeoflife
|
| 128 |
+
Trimeresurus kanburiensis,Animalia Chordata Squamata Viperidae Trimeresurus kanburiensis with common name Kanburi pit viper,treeoflife
|
| 129 |
+
Trimeresurus lanna,Animalia Chordata Squamata Viperidae Trimeresurus lanna,congener_ranks
|
| 130 |
+
Trimeresurus macrops,Animalia Chordata Squamata Viperidae Trimeresurus macrops with common name Kramer's pit viper,treeoflife
|
| 131 |
+
Trimeresurus phuketensis,Animalia Chordata Squamata Viperidae Trimeresurus phuketensis with common name Phuket pitviper,treeoflife
|
| 132 |
+
Trimeresurus popeiorum,Animalia Chordata Squamata Viperidae Trimeresurus popeiorum with common name Pope's bamboo pit viper,treeoflife
|
| 133 |
+
Trimeresurus purpureomaculatus,Animalia Chordata Squamata Viperidae Trimeresurus purpureomaculatus with common name Shore pit viper,treeoflife
|
| 134 |
+
Trimeresurus sabahi,Animalia Chordata Squamata Viperidae Trimeresurus sabahi with common name Sabah bamboo pit viper,treeoflife
|
| 135 |
+
Trimeresurus venustus,Animalia Chordata Squamata Viperidae Trimeresurus venustus with common name Brown-spotted pit viper,treeoflife
|
| 136 |
+
Trimeresurus vogeli,Animalia Chordata Squamata Viperidae Trimeresurus vogeli with common name Vogel's pit viper,treeoflife
|
| 137 |
+
Trimerodytes yunnanensis,Animalia Chordata Squamata Colubridae Trimerodytes yunnanensis with common name Yunnan keelback water snake,treeoflife
|
| 138 |
+
Tropidolaemus wagleri,Animalia Chordata Squamata Viperidae Tropidolaemus wagleri with common name Wagler's palm viper,treeoflife
|
| 139 |
+
Xenochrophis trianguligerus,Animalia Chordata Squamata Colubridae Xenochrophis trianguligerus with common name Triangle keelback,treeoflife
|
| 140 |
+
Xenopeltis unicolor,Animalia Chordata Squamata Xenopeltidae Xenopeltis unicolor with common name Sunbeam snake,treeoflife
|
benchmark_v4/embeddings/bioclip2_zero_shot_text_weights.npy
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:47fd63ae07653d8d0ebf87945817a04288a0e431c1aff9a1e202c756af8d9981
|
| 3 |
+
size 427136
|
benchmark_v4/embeddings/checksums.json
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"bioclip2_vitl14.npy": "3b6abc61ed323e3b359a04a731ce0381633796879aee0108b0af32516a6e6285",
|
| 3 |
+
"bioclip2_zero_shot_class_texts.csv": "b7bb97e5eed967db9a6620ba28532bc5842e1cfedc7c44476d89eb4eadda8d8a",
|
| 4 |
+
"bioclip2_zero_shot_text_weights.npy": "47fd63ae07653d8d0ebf87945817a04288a0e431c1aff9a1e202c756af8d9981",
|
| 5 |
+
"classes.json": "7d172f0d47b57407bc6195ffe713c8907aea500ee933ceb23dc54e4447207fdd",
|
| 6 |
+
"clip_vitl14_laion2b.npy": "d259ac97511466c198fb1d1b1c386bf6a220af3504c3240a6a2eb7804c7bec7b",
|
| 7 |
+
"dinov2_vitb14_reg4.npy": "92c4a5937cecc8209b8e7276ca8f9e08324a9d102535ec4f9b6283f340c1a2de",
|
| 8 |
+
"example_probe.py": "cb0c2e5fef47dfa3bb860b7f5c79f8376ea7a74e90f87e91b11009305267ed2b",
|
| 9 |
+
"index.csv": "e0dfb4b0f0e15ef2a6e32656c9dede7322e2d8c8f5ab8a56a9d042581ddcbf2e",
|
| 10 |
+
"README.md": "9ac9450eeedfff15c94a0d1d98a93d61bb92ffc6e61560003835a5cdf704f4c8"
|
| 11 |
+
}
|
benchmark_v4/embeddings/classes.json
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
"Acrochordus granulatus",
|
| 3 |
+
"Acrochordus javanicus",
|
| 4 |
+
"Ahaetulla fasciolata",
|
| 5 |
+
"Ahaetulla nasuta",
|
| 6 |
+
"Ahaetulla prasina",
|
| 7 |
+
"Amphiesma stolatum",
|
| 8 |
+
"Aplopeltura boa",
|
| 9 |
+
"Argyrophis diardii",
|
| 10 |
+
"Argyrophis muelleri",
|
| 11 |
+
"Asthenodipsas malaccana",
|
| 12 |
+
"Boiga bengkuluensis",
|
| 13 |
+
"Boiga cyanea",
|
| 14 |
+
"Boiga cynodon",
|
| 15 |
+
"Boiga drapiezii",
|
| 16 |
+
"Boiga melanota",
|
| 17 |
+
"Boiga multomaculata",
|
| 18 |
+
"Boiga nigriceps",
|
| 19 |
+
"Boiga siamensis",
|
| 20 |
+
"Bungarus fasciatus",
|
| 21 |
+
"Bungarus flaviceps",
|
| 22 |
+
"Bungarus wanghaotingi",
|
| 23 |
+
"Calamaria lumbricoidea",
|
| 24 |
+
"Calamaria pavimentata",
|
| 25 |
+
"Calliophis bivirgatus",
|
| 26 |
+
"Calliophis gracilis",
|
| 27 |
+
"Calliophis intestinalis",
|
| 28 |
+
"Calliophis maculiceps",
|
| 29 |
+
"Calloselasma rhodostoma",
|
| 30 |
+
"Cantoria violacea",
|
| 31 |
+
"Cerberus schneiderii",
|
| 32 |
+
"Chrysopelea ornata",
|
| 33 |
+
"Chrysopelea paradisi",
|
| 34 |
+
"Chrysopelea pelias",
|
| 35 |
+
"Coelognathus flavolineatus",
|
| 36 |
+
"Coelognathus radiatus",
|
| 37 |
+
"Cylindrophis jodiae",
|
| 38 |
+
"Daboia siamensis",
|
| 39 |
+
"Dendrelaphis caudolineatus",
|
| 40 |
+
"Dendrelaphis cyanochloris",
|
| 41 |
+
"Dendrelaphis formosus",
|
| 42 |
+
"Dendrelaphis haasi",
|
| 43 |
+
"Dendrelaphis kopsteini",
|
| 44 |
+
"Dendrelaphis nigroserratus",
|
| 45 |
+
"Dendrelaphis pictus",
|
| 46 |
+
"Dendrelaphis striatus",
|
| 47 |
+
"Dendrelaphis subocularis",
|
| 48 |
+
"Dendrelaphis vogeli",
|
| 49 |
+
"Dryophiops rubescens",
|
| 50 |
+
"Elaphe taeniura",
|
| 51 |
+
"Enhydris chanardi",
|
| 52 |
+
"Enhydris enhydris",
|
| 53 |
+
"Enhydris subtaeniata",
|
| 54 |
+
"Erpeton tentaculatum",
|
| 55 |
+
"Fowlea flavipunctatus",
|
| 56 |
+
"Fowlea piscator",
|
| 57 |
+
"Gongylosoma scriptum",
|
| 58 |
+
"Gonyosoma oxycephalum",
|
| 59 |
+
"Hebius deschauenseei",
|
| 60 |
+
"Hebius khasiensis",
|
| 61 |
+
"Homalopsis buccata",
|
| 62 |
+
"Homalopsis mereljcoxi",
|
| 63 |
+
"Homalopsis nigroventralis",
|
| 64 |
+
"Hydrophis curtus",
|
| 65 |
+
"Hydrophis cyanocinctus",
|
| 66 |
+
"Hydrophis platurus",
|
| 67 |
+
"Hypsiscopus plumbea",
|
| 68 |
+
"Indotyphlops braminus",
|
| 69 |
+
"Indotyphlops porrectus",
|
| 70 |
+
"Laticauda colubrina",
|
| 71 |
+
"Laticauda laticaudata",
|
| 72 |
+
"Lycodon capucinus",
|
| 73 |
+
"Lycodon cardamomensis",
|
| 74 |
+
"Lycodon davisonii",
|
| 75 |
+
"Lycodon effraenis",
|
| 76 |
+
"Lycodon fasciatus",
|
| 77 |
+
"Lycodon laoensis",
|
| 78 |
+
"Lycodon ophiophagus",
|
| 79 |
+
"Lycodon septentrionalis",
|
| 80 |
+
"Lycodon subannulatus",
|
| 81 |
+
"Lycodon subcinctus",
|
| 82 |
+
"Malayopython reticulatus",
|
| 83 |
+
"Naja kaouthia",
|
| 84 |
+
"Naja siamensis",
|
| 85 |
+
"Naja sumatrana",
|
| 86 |
+
"Oligodon barroni",
|
| 87 |
+
"Oligodon cinereus",
|
| 88 |
+
"Oligodon cyclurus",
|
| 89 |
+
"Oligodon deuvei",
|
| 90 |
+
"Oligodon fasciolatus",
|
| 91 |
+
"Oligodon mouhoti",
|
| 92 |
+
"Oligodon phangan",
|
| 93 |
+
"Oligodon purpurascens",
|
| 94 |
+
"Oligodon signatus",
|
| 95 |
+
"Oligodon taeniatus",
|
| 96 |
+
"Ophiophagus hannah",
|
| 97 |
+
"Oreocryptophis porphyraceus",
|
| 98 |
+
"Ovophis monticola",
|
| 99 |
+
"Pareas berdmorei",
|
| 100 |
+
"Pareas carinatus",
|
| 101 |
+
"Pareas hamptoni",
|
| 102 |
+
"Pareas macularius",
|
| 103 |
+
"Pareas margaritophorus",
|
| 104 |
+
"Plagiopholis nuchalis",
|
| 105 |
+
"Psammodynastes pulverulentus",
|
| 106 |
+
"Psammophis indochinensis",
|
| 107 |
+
"Pseudorabdion longiceps",
|
| 108 |
+
"Pseudoxenodon macrops",
|
| 109 |
+
"Ptyas carinata",
|
| 110 |
+
"Ptyas fusca",
|
| 111 |
+
"Ptyas korros",
|
| 112 |
+
"Ptyas mucosa",
|
| 113 |
+
"Python bivittatus",
|
| 114 |
+
"Python brongersmai",
|
| 115 |
+
"Rhabdophis chrysargos",
|
| 116 |
+
"Rhabdophis nigrocinctus",
|
| 117 |
+
"Rhabdophis subminiatus",
|
| 118 |
+
"Sibynophis collaris",
|
| 119 |
+
"Sibynophis melanocephalus",
|
| 120 |
+
"Sibynophis triangularis",
|
| 121 |
+
"Sinomicrurus macclellandi",
|
| 122 |
+
"Subsessor bocourti",
|
| 123 |
+
"Trimeresurus albolabris",
|
| 124 |
+
"Trimeresurus cardamomensis",
|
| 125 |
+
"Trimeresurus gumprechti",
|
| 126 |
+
"Trimeresurus guoi",
|
| 127 |
+
"Trimeresurus hageni",
|
| 128 |
+
"Trimeresurus kanburiensis",
|
| 129 |
+
"Trimeresurus lanna",
|
| 130 |
+
"Trimeresurus macrops",
|
| 131 |
+
"Trimeresurus phuketensis",
|
| 132 |
+
"Trimeresurus popeiorum",
|
| 133 |
+
"Trimeresurus purpureomaculatus",
|
| 134 |
+
"Trimeresurus sabahi",
|
| 135 |
+
"Trimeresurus venustus",
|
| 136 |
+
"Trimeresurus vogeli",
|
| 137 |
+
"Trimerodytes yunnanensis",
|
| 138 |
+
"Tropidolaemus wagleri",
|
| 139 |
+
"Xenochrophis trianguligerus",
|
| 140 |
+
"Xenopeltis unicolor"
|
| 141 |
+
]
|
benchmark_v4/embeddings/clip_vitl14_laion2b.npy
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d259ac97511466c198fb1d1b1c386bf6a220af3504c3240a6a2eb7804c7bec7b
|
| 3 |
+
size 81002624
|
benchmark_v4/embeddings/dinov2_vitb14_reg4.npy
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:92c4a5937cecc8209b8e7276ca8f9e08324a9d102535ec4f9b6283f340c1a2de
|
| 3 |
+
size 81002624
|
benchmark_v4/embeddings/example_probe.py
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Train and score classifiers on the frozen embeddings of the Thai snake benchmark.
|
| 2 |
+
|
| 3 |
+
Usage:
|
| 4 |
+
python example_probe.py bioclip2_vitl14.npy # logistic-regression probe, locked test set
|
| 5 |
+
python example_probe.py dinov2_vitb14_reg4.npy --cv # the same probe, five grouped CV folds
|
| 6 |
+
python example_probe.py bioclip2_vitl14.npy --zero-shot # BioCLIP 2 zero-shot with its text classifier
|
| 7 |
+
|
| 8 |
+
The probe is the one reported in the paper: features standardized on the training images, then class-balanced
|
| 9 |
+
multinomial logistic regression (C = 1, L2, lbfgs, max_iter = 2000, tol = 1e-5). It is trained on all development
|
| 10 |
+
images and scored once on the test images (or, with --cv, trained on four folds and scored on the fifth). Test
|
| 11 |
+
accuracy with this script: BioCLIP 2 62.5%, DINOv2 51.8%, CLIP ViT-L/14 36.2%; BioCLIP 2 zero-shot 44.3%. The paper
|
| 12 |
+
reports 62.4%, 51.8% and 36.0% for the probes: the solver stops at a tolerance, so the result shifts slightly with
|
| 13 |
+
the order of the training rows.
|
| 14 |
+
Requires numpy, pandas and scikit-learn.
|
| 15 |
+
"""
|
| 16 |
+
import argparse
|
| 17 |
+
import json
|
| 18 |
+
from pathlib import Path
|
| 19 |
+
|
| 20 |
+
import numpy as np
|
| 21 |
+
import pandas as pd
|
| 22 |
+
from sklearn.linear_model import LogisticRegression
|
| 23 |
+
from sklearn.pipeline import make_pipeline
|
| 24 |
+
from sklearn.preprocessing import StandardScaler
|
| 25 |
+
|
| 26 |
+
HERE = Path(__file__).resolve().parent
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def probe(x_train, y_train, x_eval, n_classes):
|
| 30 |
+
model = make_pipeline(StandardScaler(), LogisticRegression(
|
| 31 |
+
C=1.0, class_weight="balanced", solver="lbfgs", max_iter=2000, tol=1e-5))
|
| 32 |
+
model.fit(x_train, y_train)
|
| 33 |
+
probs = np.zeros((len(x_eval), n_classes))
|
| 34 |
+
probs[:, model[-1].classes_] = model.predict_proba(x_eval) # species absent from training get probability 0
|
| 35 |
+
return probs
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def main():
|
| 39 |
+
parser = argparse.ArgumentParser()
|
| 40 |
+
parser.add_argument("embeddings")
|
| 41 |
+
parser.add_argument("--cv", action="store_true", help="five grouped cross-validation folds on development")
|
| 42 |
+
parser.add_argument("--zero-shot", action="store_true", help="BioCLIP 2 zero-shot (bioclip2_vitl14.npy only)")
|
| 43 |
+
args = parser.parse_args()
|
| 44 |
+
|
| 45 |
+
x = np.load(HERE / args.embeddings).astype(np.float64)
|
| 46 |
+
index = pd.read_csv(HERE / "index.csv", dtype={"cv_fold": str}, keep_default_na=False)
|
| 47 |
+
classes = json.loads((HERE / "classes.json").read_text(encoding="utf-8"))
|
| 48 |
+
y = index.label_id.to_numpy()
|
| 49 |
+
test = (index.split == "test").to_numpy()
|
| 50 |
+
|
| 51 |
+
if args.zero_shot:
|
| 52 |
+
weights = np.load(HERE / "bioclip2_zero_shot_text_weights.npy").astype(np.float64)
|
| 53 |
+
pred = (100.0 * x[test] @ weights.T).argmax(1)
|
| 54 |
+
print(f"zero-shot test accuracy: {(pred == y[test]).mean():.4f} ({test.sum()} images)")
|
| 55 |
+
return
|
| 56 |
+
if args.cv:
|
| 57 |
+
scores = []
|
| 58 |
+
for fold in sorted(index.cv_fold[~test].unique()):
|
| 59 |
+
train = ~test & (index.cv_fold != fold).to_numpy()
|
| 60 |
+
held = (index.cv_fold == fold).to_numpy()
|
| 61 |
+
pred = probe(x[train], y[train], x[held], len(classes)).argmax(1)
|
| 62 |
+
scores.append((pred == y[held]).mean())
|
| 63 |
+
print(f"fold {fold}: accuracy {scores[-1]:.4f} ({held.sum()} images)")
|
| 64 |
+
print(f"CV accuracy: {np.mean(scores):.4f} +/- {np.std(scores, ddof=1):.4f}")
|
| 65 |
+
return
|
| 66 |
+
pred = probe(x[~test], y[~test], x[test], len(classes)).argmax(1)
|
| 67 |
+
print(f"test accuracy: {(pred == y[test]).mean():.4f} ({test.sum()} images, {len(np.unique(y[test]))} species)")
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
if __name__ == "__main__":
|
| 71 |
+
main()
|
benchmark_v4/embeddings/index.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|