Update README.md
Browse files
README.md
CHANGED
@@ -4,6 +4,10 @@ datasets:
|
|
4 |
- TNILab/DomainNet_FL
|
5 |
---
|
6 |
|
|
|
|
|
|
|
|
|
7 |

|
8 |
|
9 |
```py
|
@@ -135,4 +139,221 @@ The_Great_Wall_of_China 0.8893 0.8333 0.8604 270
|
|
135 |
accuracy 0.7995 32670
|
136 |
macro avg 0.8052 0.7995 0.8006 32670
|
137 |
weighted avg 0.8052 0.7995 0.8006 32670
|
138 |
-
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
- TNILab/DomainNet_FL
|
5 |
---
|
6 |
|
7 |
+
# **Multisource-121-DomainNet**
|
8 |
+
|
9 |
+
> **Multisource-121-DomainNet** is an image classification vision-language encoder model fine-tuned from **google/siglip2-base-patch16-224** for a single-label classification task. It is designed to classify images into 121 domain categories using the **SiglipForImageClassification** architecture.
|
10 |
+
|
11 |

|
12 |
|
13 |
```py
|
|
|
139 |
accuracy 0.7995 32670
|
140 |
macro avg 0.8052 0.7995 0.8006 32670
|
141 |
weighted avg 0.8052 0.7995 0.8006 32670
|
142 |
+
```
|
143 |
+
|
144 |
+
|
145 |
+
|
146 |
+
|
147 |
+
The model categorizes images into the following 121 classes:
|
148 |
+
- **Class 0:** "barn"
|
149 |
+
- **Class 1:** "baseball_bat"
|
150 |
+
- **Class 2:** "basket"
|
151 |
+
- **Class 3:** "beach"
|
152 |
+
- **Class 4:** "bear"
|
153 |
+
- **Class 5:** "beard"
|
154 |
+
- **Class 6:** "bee"
|
155 |
+
- **Class 7:** "bird"
|
156 |
+
- **Class 8:** "blueberry"
|
157 |
+
- **Class 9:** "bowtie"
|
158 |
+
- **Class 10:** "bracelet"
|
159 |
+
- **Class 11:** "brain"
|
160 |
+
- **Class 12:** "bread"
|
161 |
+
- **Class 13:** "broccoli"
|
162 |
+
- **Class 14:** "bus"
|
163 |
+
- **Class 15:** "butterfly"
|
164 |
+
- **Class 16:** "circle"
|
165 |
+
- **Class 17:** "cloud"
|
166 |
+
- **Class 18:** "cruise_ship"
|
167 |
+
- **Class 19:** "dolphin"
|
168 |
+
- **Class 20:** "dumbbell"
|
169 |
+
- **Class 21:** "elephant"
|
170 |
+
- **Class 22:** "eye"
|
171 |
+
- **Class 23:** "eyeglasses"
|
172 |
+
- **Class 24:** "feather"
|
173 |
+
- **Class 25:** "fish"
|
174 |
+
- **Class 26:** "flower"
|
175 |
+
- **Class 27:** "foot"
|
176 |
+
- **Class 28:** "frog"
|
177 |
+
- **Class 29:** "giraffe"
|
178 |
+
- **Class 30:** "goatee"
|
179 |
+
- **Class 31:** "golf_club"
|
180 |
+
- **Class 32:** "grapes"
|
181 |
+
- **Class 33:** "grass"
|
182 |
+
- **Class 34:** "guitar"
|
183 |
+
- **Class 35:** "hamburger"
|
184 |
+
- **Class 36:** "hand"
|
185 |
+
- **Class 37:** "hat"
|
186 |
+
- **Class 38:** "headphones"
|
187 |
+
- **Class 39:** "helicopter"
|
188 |
+
- **Class 40:** "hexagon"
|
189 |
+
- **Class 41:** "hockey_stick"
|
190 |
+
- **Class 42:** "horse"
|
191 |
+
- **Class 43:** "hourglass"
|
192 |
+
- **Class 44:** "house"
|
193 |
+
- **Class 45:** "ice_cream"
|
194 |
+
- **Class 46:** "jacket"
|
195 |
+
- **Class 47:** "ladder"
|
196 |
+
- **Class 48:** "leg"
|
197 |
+
- **Class 49:** "lipstick"
|
198 |
+
- **Class 50:** "megaphone"
|
199 |
+
- **Class 51:** "monkey"
|
200 |
+
- **Class 52:** "moon"
|
201 |
+
- **Class 53:** "mushroom"
|
202 |
+
- **Class 54:** "necklace"
|
203 |
+
- **Class 55:** "owl"
|
204 |
+
- **Class 56:** "panda"
|
205 |
+
- **Class 57:** "pear"
|
206 |
+
- **Class 58:** "peas"
|
207 |
+
- **Class 59:** "penguin"
|
208 |
+
- **Class 60:** "pig"
|
209 |
+
- **Class 61:** "pillow"
|
210 |
+
- **Class 62:** "pineapple"
|
211 |
+
- **Class 63:** "pizza"
|
212 |
+
- **Class 64:** "pool"
|
213 |
+
- **Class 65:** "popsicle"
|
214 |
+
- **Class 66:** "rabbit"
|
215 |
+
- **Class 67:** "rhinoceros"
|
216 |
+
- **Class 68:** "rifle"
|
217 |
+
- **Class 69:** "river"
|
218 |
+
- **Class 70:** "sailboat"
|
219 |
+
- **Class 71:** "sandwich"
|
220 |
+
- **Class 72:** "sea_turtle"
|
221 |
+
- **Class 73:** "shark"
|
222 |
+
- **Class 74:** "shoe"
|
223 |
+
- **Class 75:** "skyscraper"
|
224 |
+
- **Class 76:** "snorkel"
|
225 |
+
- **Class 77:** "snowman"
|
226 |
+
- **Class 78:** "soccer_ball"
|
227 |
+
- **Class 79:** "speedboat"
|
228 |
+
- **Class 80:** "spider"
|
229 |
+
- **Class 81:** "spoon"
|
230 |
+
- **Class 82:** "square"
|
231 |
+
- **Class 83:** "squirrel"
|
232 |
+
- **Class 84:** "stethoscope"
|
233 |
+
- **Class 85:** "strawberry"
|
234 |
+
- **Class 86:** "streetlight"
|
235 |
+
- **Class 87:** "submarine"
|
236 |
+
- **Class 88:** "suitcase"
|
237 |
+
- **Class 89:** "sun"
|
238 |
+
- **Class 90:** "sweater"
|
239 |
+
- **Class 91:** "sword"
|
240 |
+
- **Class 92:** "table"
|
241 |
+
- **Class 93:** "teapot"
|
242 |
+
- **Class 94:** "teddy-bear"
|
243 |
+
- **Class 95:** "telephone"
|
244 |
+
- **Class 96:** "tent"
|
245 |
+
- **Class 97:** "The_Eiffel_Tower"
|
246 |
+
- **Class 98:** "The_Great_Wall_of_China"
|
247 |
+
- **Class 99:** "The_Mona_Lisa"
|
248 |
+
- **Class 100:** "tiger"
|
249 |
+
- **Class 101:** "toaster"
|
250 |
+
- **Class 102:** "tooth"
|
251 |
+
- **Class 103:** "tornado"
|
252 |
+
- **Class 104:** "tractor"
|
253 |
+
- **Class 105:** "train"
|
254 |
+
- **Class 106:** "tree"
|
255 |
+
- **Class 107:** "triangle"
|
256 |
+
- **Class 108:** "trombone"
|
257 |
+
- **Class 109:** "truck"
|
258 |
+
- **Class 110:** "trumpet"
|
259 |
+
- **Class 111:** "umbrella"
|
260 |
+
- **Class 112:** "vase"
|
261 |
+
- **Class 113:** "violin"
|
262 |
+
- **Class 114:** "watermelon"
|
263 |
+
- **Class 115:** "whale"
|
264 |
+
- **Class 116:** "windmill"
|
265 |
+
- **Class 117:** "wine_glass"
|
266 |
+
- **Class 118:** "yoga"
|
267 |
+
- **Class 119:** "zebra"
|
268 |
+
- **Class 120:** "zigzag"
|
269 |
+
|
270 |
+
# **Run with Transformers🤗**
|
271 |
+
|
272 |
+
```python
|
273 |
+
!pip install -q transformers torch pillow gradio
|
274 |
+
```
|
275 |
+
|
276 |
+
```python
|
277 |
+
import gradio as gr
|
278 |
+
from transformers import AutoImageProcessor, SiglipForImageClassification
|
279 |
+
from transformers.image_utils import load_image
|
280 |
+
from PIL import Image
|
281 |
+
import torch
|
282 |
+
|
283 |
+
# Load model and processor
|
284 |
+
model_name = "prithivMLmods/Multisource-121-DomainNet"
|
285 |
+
model = SiglipForImageClassification.from_pretrained(model_name)
|
286 |
+
processor = AutoImageProcessor.from_pretrained(model_name)
|
287 |
+
|
288 |
+
def multisource_classification(image):
|
289 |
+
"""Predicts the domain category for an input image."""
|
290 |
+
# Convert the input numpy array to a PIL Image and ensure it is in RGB format
|
291 |
+
image = Image.fromarray(image).convert("RGB")
|
292 |
+
|
293 |
+
# Process the image and convert it to model inputs
|
294 |
+
inputs = processor(images=image, return_tensors="pt")
|
295 |
+
|
296 |
+
# Get model predictions without gradient calculations
|
297 |
+
with torch.no_grad():
|
298 |
+
outputs = model(**inputs)
|
299 |
+
logits = outputs.logits
|
300 |
+
# Convert logits to probabilities using softmax
|
301 |
+
probs = torch.nn.functional.softmax(logits, dim=1).squeeze().tolist()
|
302 |
+
|
303 |
+
# Mapping from class indices to domain labels
|
304 |
+
labels = {
|
305 |
+
"0": "barn", "1": "baseball_bat", "2": "basket", "3": "beach", "4": "bear",
|
306 |
+
"5": "beard", "6": "bee", "7": "bird", "8": "blueberry", "9": "bowtie",
|
307 |
+
"10": "bracelet", "11": "brain", "12": "bread", "13": "broccoli", "14": "bus",
|
308 |
+
"15": "butterfly", "16": "circle", "17": "cloud", "18": "cruise_ship", "19": "dolphin",
|
309 |
+
"20": "dumbbell", "21": "elephant", "22": "eye", "23": "eyeglasses", "24": "feather",
|
310 |
+
"25": "fish", "26": "flower", "27": "foot", "28": "frog", "29": "giraffe",
|
311 |
+
"30": "goatee", "31": "golf_club", "32": "grapes", "33": "grass", "34": "guitar",
|
312 |
+
"35": "hamburger", "36": "hand", "37": "hat", "38": "headphones", "39": "helicopter",
|
313 |
+
"40": "hexagon", "41": "hockey_stick", "42": "horse", "43": "hourglass", "44": "house",
|
314 |
+
"45": "ice_cream", "46": "jacket", "47": "ladder", "48": "leg", "49": "lipstick",
|
315 |
+
"50": "megaphone", "51": "monkey", "52": "moon", "53": "mushroom", "54": "necklace",
|
316 |
+
"55": "owl", "56": "panda", "57": "pear", "58": "peas", "59": "penguin",
|
317 |
+
"60": "pig", "61": "pillow", "62": "pineapple", "63": "pizza", "64": "pool",
|
318 |
+
"65": "popsicle", "66": "rabbit", "67": "rhinoceros", "68": "rifle", "69": "river",
|
319 |
+
"70": "sailboat", "71": "sandwich", "72": "sea_turtle", "73": "shark", "74": "shoe",
|
320 |
+
"75": "skyscraper", "76": "snorkel", "77": "snowman", "78": "soccer_ball", "79": "speedboat",
|
321 |
+
"80": "spider", "81": "spoon", "82": "square", "83": "squirrel", "84": "stethoscope",
|
322 |
+
"85": "strawberry", "86": "streetlight", "87": "submarine", "88": "suitcase", "89": "sun",
|
323 |
+
"90": "sweater", "91": "sword", "92": "table", "93": "teapot", "94": "teddy-bear",
|
324 |
+
"95": "telephone", "96": "tent", "97": "The_Eiffel_Tower", "98": "The_Great_Wall_of_China",
|
325 |
+
"99": "The_Mona_Lisa", "100": "tiger", "101": "toaster", "102": "tooth", "103": "tornado",
|
326 |
+
"104": "tractor", "105": "train", "106": "tree", "107": "triangle", "108": "trombone",
|
327 |
+
"109": "truck", "110": "trumpet", "111": "umbrella", "112": "vase", "113": "violin",
|
328 |
+
"114": "watermelon", "115": "whale", "116": "windmill", "117": "wine_glass", "118": "yoga",
|
329 |
+
"119": "zebra", "120": "zigzag"
|
330 |
+
}
|
331 |
+
|
332 |
+
# Create a dictionary mapping each label to its corresponding probability (rounded)
|
333 |
+
predictions = {labels[str(i)]: round(probs[i], 3) for i in range(len(probs))}
|
334 |
+
return predictions
|
335 |
+
|
336 |
+
# Create Gradio interface
|
337 |
+
iface = gr.Interface(
|
338 |
+
fn=multisource_classification,
|
339 |
+
inputs=gr.Image(type="numpy"),
|
340 |
+
outputs=gr.Label(label="Prediction Scores"),
|
341 |
+
title="Multisource-121-DomainNet Classification",
|
342 |
+
description="Upload an image to classify it into one of 121 domain categories."
|
343 |
+
)
|
344 |
+
|
345 |
+
# Launch the app
|
346 |
+
if __name__ == "__main__":
|
347 |
+
iface.launch()
|
348 |
+
```
|
349 |
+
|
350 |
+
---
|
351 |
+
|
352 |
+
# **Intended Use:**
|
353 |
+
|
354 |
+
The **Multisource-121-DomainNet** model is designed for multi-source image classification. It can categorize images into a diverse set of 121 domains, covering various objects, scenes, and landmarks. Potential use cases include:
|
355 |
+
|
356 |
+
- **Cross-Domain Image Analysis:** Enabling robust classification across a wide range of visual domains.
|
357 |
+
- **Multimedia Retrieval:** Assisting in content organization and retrieval in multimedia databases.
|
358 |
+
- **Computer Vision Research:** Serving as a benchmark for evaluating domain adaptation and transfer learning techniques.
|
359 |
+
- **Interactive Applications:** Enhancing user interfaces with diverse, real-time image recognition capabilities.
|