Update README.md
Browse files
README.md
CHANGED
|
@@ -2,15 +2,21 @@
|
|
| 2 |
license: apache-2.0
|
| 3 |
datasets:
|
| 4 |
- prithivMLmods/BnW-vs-Colored-10K
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
---
|
| 6 |
|
| 7 |

|
| 8 |
|
| 9 |
-
# **BnW-vs-Colored-Detection**
|
| 10 |
-
|
| 11 |
-
> **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.
|
| 12 |
-
|
| 13 |
-
|
| 14 |
```py
|
| 15 |
Classification Report:
|
| 16 |
precision recall f1-score support
|
|
@@ -23,78 +29,4 @@ Classification Report:
|
|
| 23 |
weighted avg 0.9989 0.9989 0.9989 10000
|
| 24 |
```
|
| 25 |
|
| 26 |
-

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

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

|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|