Update README.md
Browse files
README.md
CHANGED
@@ -17,6 +17,10 @@ tags:
|
|
17 |
|
18 |

|
19 |
|
|
|
|
|
|
|
|
|
20 |
```py
|
21 |
Classification Report:
|
22 |
precision recall f1-score support
|
@@ -29,4 +33,77 @@ Classification Report:
|
|
29 |
weighted avg 0.9989 0.9989 0.9989 10000
|
30 |
```
|
31 |
|
32 |
-

|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |

|
19 |
|
20 |
+
# **BnW-vs-Colored-Detection**
|
21 |
+
|
22 |
+
> **BnW-vs-Colored-Detection** 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 distinguish between black & white and colored images using the **SiglipForImageClassification** architecture.
|
23 |
+
|
24 |
```py
|
25 |
Classification Report:
|
26 |
precision recall f1-score support
|
|
|
33 |
weighted avg 0.9989 0.9989 0.9989 10000
|
34 |
```
|
35 |
|
36 |
+

|
37 |
+
|
38 |
+
---
|
39 |
+
|
40 |
+
The model categorizes images into 2 classes:
|
41 |
+
|
42 |
+
```
|
43 |
+
Class 0: "B & W"
|
44 |
+
Class 1: "Colored"
|
45 |
+
```
|
46 |
+
|
47 |
+
---
|
48 |
+
|
49 |
+
## **Install dependencies**
|
50 |
+
|
51 |
+
```python
|
52 |
+
!pip install -q transformers torch pillow gradio
|
53 |
+
```
|
54 |
+
|
55 |
+
---
|
56 |
+
|
57 |
+
## **Inference Code**
|
58 |
+
|
59 |
+
```python
|
60 |
+
import gradio as gr
|
61 |
+
from transformers import AutoImageProcessor, SiglipForImageClassification
|
62 |
+
from PIL import Image
|
63 |
+
import torch
|
64 |
+
|
65 |
+
# Load model and processor
|
66 |
+
model_name = "prithivMLmods/BnW-vs-Colored-Detection" # Updated model name
|
67 |
+
model = SiglipForImageClassification.from_pretrained(model_name)
|
68 |
+
processor = AutoImageProcessor.from_pretrained(model_name)
|
69 |
+
|
70 |
+
def classify_bw_colored(image):
|
71 |
+
"""Predicts if an image is Black & White or Colored."""
|
72 |
+
image = Image.fromarray(image).convert("RGB")
|
73 |
+
inputs = processor(images=image, return_tensors="pt")
|
74 |
+
|
75 |
+
with torch.no_grad():
|
76 |
+
outputs = model(**inputs)
|
77 |
+
logits = outputs.logits
|
78 |
+
probs = torch.nn.functional.softmax(logits, dim=1).squeeze().tolist()
|
79 |
+
|
80 |
+
labels = {
|
81 |
+
"0": "B & W", "1": "Colored"
|
82 |
+
}
|
83 |
+
predictions = {labels[str(i)]: round(probs[i], 3) for i in range(len(probs))}
|
84 |
+
|
85 |
+
return predictions
|
86 |
+
|
87 |
+
# Create Gradio interface
|
88 |
+
iface = gr.Interface(
|
89 |
+
fn=classify_bw_colored,
|
90 |
+
inputs=gr.Image(type="numpy"),
|
91 |
+
outputs=gr.Label(label="Prediction Scores"),
|
92 |
+
title="BnW vs Colored Detection",
|
93 |
+
description="Upload an image to detect if it is Black & White or Colored."
|
94 |
+
)
|
95 |
+
|
96 |
+
if __name__ == "__main__":
|
97 |
+
iface.launch()
|
98 |
+
```
|
99 |
+
|
100 |
+
---
|
101 |
+
|
102 |
+
## **Intended Use:**
|
103 |
+
|
104 |
+
The **BnW-vs-Colored-Detection** model is designed to classify images by color mode. Potential use cases include:
|
105 |
+
|
106 |
+
- **Archive Organization:** Separate historical B&W images from modern colored ones.
|
107 |
+
- **Data Filtering:** Preprocess image datasets by removing or labeling specific types.
|
108 |
+
- **Digital Restoration:** Assist in determining candidates for colorization.
|
109 |
+
- **Search & Categorization:** Enable efficient tagging and filtering in image libraries.
|