Files changed (1) hide show
  1. README.md +164 -149
README.md CHANGED
@@ -1,149 +1,164 @@
1
- ---
2
- library_name: transformers
3
- tags:
4
- - siglip
5
- - siglip2
6
- - vision
7
- - clip
8
- - image-embeddings
9
- - pet-recognition
10
- model_id: AvitoTech/SigLIP2-giant-for-animal-identification
11
- pipeline_tag: image-feature-extraction
12
- ---
13
-
14
- # SigLIP2-Giant Fine-tuned for Animal Identification
15
-
16
- Fine-tuned SigLIP2-Giant model for individual animal identification, specializing in distinguishing between unique cats and dogs. This model produces robust image embeddings optimized for pet recognition, re-identification, and verification tasks.
17
-
18
-
19
- ## Model Details
20
-
21
- - **Base Model**: google/siglip2-giant-opt-patch16-384
22
- - **Input**: Images (384x384)
23
- - **Output**: Image embeddings (1152-dimensional)
24
- - **Task**: Individual animal identification and verification
25
-
26
- ## Training Data
27
-
28
- The model was trained on a comprehensive dataset combining multiple sources:
29
-
30
- - **[PetFace Dataset](https://arxiv.org/abs/2407.13555)**: Large-scale animal face dataset with 257,484 unique individuals across 13 animal families
31
- - **[Dogs-World](https://www.kaggle.com/datasets/lextoumbourou/dogs-world)**: Kaggle dataset for dog breed and individual identification
32
- - **[LCW (Labeled Cats in the Wild)](https://www.kaggle.com/datasets/dseidli/lcwlabeled-cats-in-the-wild)**: Cat identification dataset
33
- - **Web-scraped Data**: Additional curated images from various sources
34
-
35
- **Total Dataset Statistics:**
36
- - **1,904,157** total photographs
37
- - **695,091** unique individual animals (cats and dogs)
38
-
39
- ## Training Details
40
-
41
- **Training Configuration:**
42
- - **Batch Size**: 116 samples (58 unique identities × 2 photos each)
43
- - **Optimizer**: Adam with learning rate 1e-4
44
- - **Training Duration**: 10 epochs
45
- - **Transfer Learning**: Final 5 transformer blocks unfrozen, lower layers frozen to preserve pre-trained features
46
-
47
- **Loss Function:**
48
- The model is trained using a combined loss function consisting of:
49
- 1. **Triplet Loss** (margin α=0.45): Encourages separation between different animal identities
50
- 2. **Intra-Pair Variance Regularization** (ε=0.01): Promotes consistency across multiple photos of the same animal
51
-
52
- Combined as: L_total = 1.0 × L_triplet + 0.5 × L_var
53
-
54
- This approach creates compact feature clusters for each individual animal while maintaining large separation between different identities.
55
-
56
- ## Performance Metrics
57
-
58
- The model has been benchmarked against various vision encoders on multiple pet recognition datasets:
59
-
60
- ### [Cat Individual Images Dataset](https://www.kaggle.com/datasets/timost1234/cat-individuals)
61
-
62
- | Model | ROC AUC | EER | Top-1 | Top-5 | Top-10 |
63
- |-------|---------|-----|-------|-------|--------|
64
- | CLIP-ViT-Base | 0.9821 | 0.0604 | 0.8359 | 0.9579 | 0.9711 |
65
- | DINOv2-Small | 0.9904 | 0.0422 | 0.8547 | 0.9660 | 0.9764 |
66
- | SigLIP-Base | 0.9899 | 0.0390 | 0.8649 | 0.9757 | 0.9842 |
67
- | SigLIP2-Base | 0.9894 | 0.0388 | 0.8660 | 0.9772 | 0.9863 |
68
- | Zer0int CLIP-L | 0.9881 | 0.0509 | 0.8768 | 0.9767 | 0.9845 |
69
- | **SigLIP2-Giant** | **0.9940** | **0.0344** | **0.8899** | **0.9868** | **0.9921** |
70
- | SigLIP2-Giant + E5-Small-v2 + gating | 0.9929 | 0.0344 | 0.8952 | 0.9872 | 0.9932 |
71
-
72
- ### [DogFaceNet Dataset](https://www.springerprofessional.de/en/a-deep-learning-approach-for-dog-face-verification-and-recogniti/17094782)
73
-
74
- | Model | ROC AUC | EER | Top-1 | Top-5 | Top-10 |
75
- |-------|---------|-----|-------|-------|--------|
76
- | CLIP-ViT-Base | 0.9739 | 0.0772 | 0.4350 | 0.6417 | 0.7204 |
77
- | DINOv2-Small | 0.9829 | 0.0571 | 0.5581 | 0.7540 | 0.8139 |
78
- | SigLIP-Base | 0.9792 | 0.0606 | 0.5848 | 0.7746 | 0.8319 |
79
- | SigLIP2-Base | 0.9776 | 0.0672 | 0.5925 | 0.7856 | 0.8422 |
80
- | Zer0int CLIP-L | 0.9814 | 0.0625 | 0.6289 | 0.8092 | 0.8597 |
81
- | **SigLIP2-Giant** | **0.9926** | **0.0326** | **0.7475** | **0.9009** | **0.9316** |
82
- | SigLIP2-Giant + E5-Small-v2 + gating | 0.9920 | 0.0314 | 0.7818 | 0.9233 | 0.9482 |
83
-
84
- ### Combined Test Dataset (Overall Performance)
85
-
86
- | Model | ROC AUC | EER | Top-1 | Top-5 | Top-10 |
87
- |-------|---------|-----|-------|-------|--------|
88
- | CLIP-ViT-Base | 0.9752 | 0.0729 | 0.6511 | 0.8122 | 0.8555 |
89
- | DINOv2-Small | 0.9848 | 0.0546 | 0.7180 | 0.8678 | 0.9009 |
90
- | SigLIP-Base | 0.9811 | 0.0572 | 0.7359 | 0.8831 | 0.9140 |
91
- | SigLIP2-Base | 0.9793 | 0.0631 | 0.7400 | 0.8889 | 0.9197 |
92
- | Zer0int CLIP-L | 0.9842 | 0.0565 | 0.7626 | 0.8994 | 0.9267 |
93
- | **SigLIP2-Giant** | **0.9912** | **0.0378** | **0.8243** | **0.9471** | **0.9641** |
94
- | SigLIP2-Giant + E5-Small-v2 + gating | 0.9882 | 0.0422 | 0.8428 | 0.9576 | 0.9722 |
95
-
96
- **Metrics Explanation:**
97
- - **ROC AUC**: Area Under the Receiver Operating Characteristic Curve - measures the model's ability to distinguish between different individuals
98
- - **EER**: Equal Error Rate - the error rate where false acceptance and false rejection rates are equal
99
- - **Top-K**: Accuracy of correct identification within the top K predictions
100
-
101
- ## Basic Usage
102
-
103
- ### Installation
104
-
105
- ```bash
106
- pip install transformers torch pillow
107
- ```
108
-
109
- ### Get Image Embedding
110
-
111
- ```python
112
- import torch
113
- import torch.nn.functional as F
114
- from PIL import Image
115
- from transformers import SiglipModel, SiglipProcessor
116
-
117
- # Load model and processor
118
- processor = SiglipProcessor.from_pretrained("google/siglip2-giant-opt-patch16-384")
119
- model = SiglipModel.from_pretrained("AvitoTech/SigLIP2-giant-for-animal-identification")
120
-
121
- device = "cuda" if torch.cuda.is_available() else "cpu"
122
- model = model.to(device).eval()
123
-
124
- # Load and process image
125
- image = Image.open("your_image.jpg").convert("RGB")
126
-
127
- with torch.no_grad():
128
- inputs = processor(images=[image], return_tensors="pt").to(device)
129
- image_features = model.get_image_features(**inputs)
130
- image_features = F.normalize(image_features, dim=1)
131
-
132
- print(f"Embedding shape: {image_features.shape}") # torch.Size([1, 1152])
133
- ```
134
-
135
- ## Citation
136
-
137
- If you use this model in your research or applications, please cite our work:
138
-
139
- ```
140
- BibTeX citation will be added upon paper publication.
141
- ```
142
-
143
- ## Use Cases
144
-
145
- - Individual pet identification and re-identification
146
- - Lost and found pet matching systems
147
- - Veterinary record management
148
- - Animal behavior monitoring
149
- - Wildlife conservation and tracking
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: transformers
3
+ tags:
4
+ - siglip
5
+ - siglip2
6
+ - vision
7
+ - clip
8
+ - image-embeddings
9
+ - pet-recognition
10
+ model_id: AvitoTech/SigLIP2-giant-for-animal-identification
11
+ pipeline_tag: image-feature-extraction
12
+ ---
13
+
14
+ # SigLIP2-Giant Fine-tuned for Animal Identification
15
+
16
+ Fine-tuned SigLIP2-Giant model for individual animal identification, specializing in distinguishing between unique cats and dogs. This model produces robust image embeddings optimized for pet recognition, re-identification, and verification tasks.
17
+
18
+
19
+ ## Model Details
20
+
21
+ - **Base Model**: google/siglip2-giant-opt-patch16-384
22
+ - **Input**: Images (384x384)
23
+ - **Output**: Image embeddings (1536-dimensional)
24
+ - **Task**: Individual animal identification and verification
25
+
26
+ ## Training Data
27
+
28
+ The model was trained on a comprehensive dataset combining multiple sources:
29
+
30
+ - **[PetFace Dataset](https://arxiv.org/abs/2407.13555)**: Large-scale animal face dataset with 257,484 unique individuals across 13 animal families
31
+ - **[Dogs-World](https://www.kaggle.com/datasets/lextoumbourou/dogs-world)**: Kaggle dataset for dog breed and individual identification
32
+ - **[LCW (Labeled Cats in the Wild)](https://www.kaggle.com/datasets/dseidli/lcwlabeled-cats-in-the-wild)**: Cat identification dataset
33
+ - **Web-scraped Data**: Additional curated images from various sources
34
+
35
+ **Total Dataset Statistics:**
36
+ - **1,904,157** total photographs
37
+ - **695,091** unique individual animals (cats and dogs)
38
+
39
+ ## Training Details
40
+
41
+ **Training Configuration:**
42
+ - **Batch Size**: 116 samples (58 unique identities × 2 photos each)
43
+ - **Optimizer**: Adam with learning rate 1e-4
44
+ - **Training Duration**: 10 epochs
45
+ - **Transfer Learning**: Final 5 transformer blocks unfrozen, lower layers frozen to preserve pre-trained features
46
+
47
+ **Loss Function:**
48
+ The model is trained using a combined loss function consisting of:
49
+ 1. **Triplet Loss** (margin α=0.45): Encourages separation between different animal identities
50
+ 2. **Intra-Pair Variance Regularization** (ε=0.01): Promotes consistency across multiple photos of the same animal
51
+
52
+ Combined as: L_total = 1.0 × L_triplet + 0.5 × L_var
53
+
54
+ This approach creates compact feature clusters for each individual animal while maintaining large separation between different identities.
55
+
56
+ ## Performance Metrics
57
+
58
+ The model has been benchmarked against various vision encoders on multiple pet recognition datasets:
59
+
60
+ ### [Cat Individual Images Dataset](https://www.kaggle.com/datasets/timost1234/cat-individuals)
61
+
62
+ | Model | ROC AUC | EER | Top-1 | Top-5 | Top-10 |
63
+ |-------|---------|-----|-------|-------|--------|
64
+ | CLIP-ViT-Base | 0.9821 | 0.0604 | 0.8359 | 0.9579 | 0.9711 |
65
+ | DINOv2-Small | 0.9904 | 0.0422 | 0.8547 | 0.9660 | 0.9764 |
66
+ | SigLIP-Base | 0.9899 | 0.0390 | 0.8649 | 0.9757 | 0.9842 |
67
+ | SigLIP2-Base | 0.9894 | 0.0388 | 0.8660 | 0.9772 | 0.9863 |
68
+ | Zer0int CLIP-L | 0.9881 | 0.0509 | 0.8768 | 0.9767 | 0.9845 |
69
+ | **SigLIP2-Giant** | **0.9940** | **0.0344** | **0.8899** | **0.9868** | **0.9921** |
70
+ | SigLIP2-Giant + E5-Small-v2 + gating | 0.9929 | 0.0344 | 0.8952 | 0.9872 | 0.9932 |
71
+
72
+ ### [DogFaceNet Dataset](https://www.springerprofessional.de/en/a-deep-learning-approach-for-dog-face-verification-and-recogniti/17094782)
73
+
74
+ | Model | ROC AUC | EER | Top-1 | Top-5 | Top-10 |
75
+ |-------|---------|-----|-------|-------|--------|
76
+ | CLIP-ViT-Base | 0.9739 | 0.0772 | 0.4350 | 0.6417 | 0.7204 |
77
+ | DINOv2-Small | 0.9829 | 0.0571 | 0.5581 | 0.7540 | 0.8139 |
78
+ | SigLIP-Base | 0.9792 | 0.0606 | 0.5848 | 0.7746 | 0.8319 |
79
+ | SigLIP2-Base | 0.9776 | 0.0672 | 0.5925 | 0.7856 | 0.8422 |
80
+ | Zer0int CLIP-L | 0.9814 | 0.0625 | 0.6289 | 0.8092 | 0.8597 |
81
+ | **SigLIP2-Giant** | **0.9926** | **0.0326** | **0.7475** | **0.9009** | **0.9316** |
82
+ | SigLIP2-Giant + E5-Small-v2 + gating | 0.9920 | 0.0314 | 0.7818 | 0.9233 | 0.9482 |
83
+
84
+ ### Combined Test Dataset (Overall Performance)
85
+
86
+ | Model | ROC AUC | EER | Top-1 | Top-5 | Top-10 |
87
+ |-------|---------|-----|-------|-------|--------|
88
+ | CLIP-ViT-Base | 0.9752 | 0.0729 | 0.6511 | 0.8122 | 0.8555 |
89
+ | DINOv2-Small | 0.9848 | 0.0546 | 0.7180 | 0.8678 | 0.9009 |
90
+ | SigLIP-Base | 0.9811 | 0.0572 | 0.7359 | 0.8831 | 0.9140 |
91
+ | SigLIP2-Base | 0.9793 | 0.0631 | 0.7400 | 0.8889 | 0.9197 |
92
+ | Zer0int CLIP-L | 0.9842 | 0.0565 | 0.7626 | 0.8994 | 0.9267 |
93
+ | **SigLIP2-Giant** | **0.9912** | **0.0378** | **0.8243** | **0.9471** | **0.9641** |
94
+ | SigLIP2-Giant + E5-Small-v2 + gating | 0.9882 | 0.0422 | 0.8428 | 0.9576 | 0.9722 |
95
+
96
+ **Metrics Explanation:**
97
+ - **ROC AUC**: Area Under the Receiver Operating Characteristic Curve - measures the model's ability to distinguish between different individuals
98
+ - **EER**: Equal Error Rate - the error rate where false acceptance and false rejection rates are equal
99
+ - **Top-K**: Accuracy of correct identification within the top K predictions
100
+
101
+ ## Basic Usage
102
+
103
+ ### Installation
104
+
105
+ ```bash
106
+ pip install transformers torch pillow
107
+ ```
108
+
109
+ ### Get Image Embedding
110
+
111
+ ```python
112
+ import torch
113
+ import torch.nn as nn
114
+ import torch.nn.functional as F
115
+ from PIL import Image
116
+ from transformers import SiglipModel, SiglipProcessor
117
+ from safetensors.torch import load_file
118
+ from huggingface_hub import hf_hub_download
119
+
120
+ class Model(nn.Module):
121
+ def __init__(self):
122
+ super().__init__()
123
+ ckpt = "google/siglip2-giant-opt-patch16-384"
124
+ self.clip = SiglipModel.from_pretrained(ckpt)
125
+ self.processor = SiglipProcessor.from_pretrained(ckpt)
126
+
127
+
128
+ def forward(self, images):
129
+ clip_inputs = self.processor(images=images, return_tensors="pt").to(self.clip.device)
130
+ return self.clip.get_image_features(**clip_inputs)
131
+
132
+ model = Model()
133
+
134
+ weights_path = hf_hub_download(repo_id="AvitoTech/SigLIP2-giant", filename="model.safetensors")
135
+ state_dict = load_file(weights_path)
136
+ model.load_state_dict(state_dict)
137
+
138
+ device = "cuda" if torch.cuda.is_available() else "cpu"
139
+ model = model.to(device).eval()
140
+
141
+ image = Image.open("your_image.jpg").convert("RGB")
142
+
143
+ with torch.no_grad():
144
+ embedding = model([image])
145
+ embedding = F.normalize(embedding, dim=1)
146
+
147
+ print(f"Embedding shape: {embedding.shape}") # torch.Size([1, 1536])
148
+ ```
149
+
150
+ ## Citation
151
+
152
+ If you use this model in your research or applications, please cite our work:
153
+
154
+ ```
155
+ BibTeX citation will be added upon paper publication.
156
+ ```
157
+
158
+ ## Use Cases
159
+
160
+ - Individual pet identification and re-identification
161
+ - Lost and found pet matching systems
162
+ - Veterinary record management
163
+ - Animal behavior monitoring
164
+ - Wildlife conservation and tracking