|
--- |
|
license: apache-2.0 |
|
datasets: |
|
- prithivMLmods/BnW-vs-Colored-10K |
|
language: |
|
- en |
|
base_model: |
|
- google/siglip2-so400m-patch16-512 |
|
pipeline_tag: image-classification |
|
library_name: transformers |
|
tags: |
|
- B&W |
|
- Colored |
|
- art |
|
- SigLIP2 |
|
--- |
|
|
|
 |
|
|
|
# **BnW-vs-Colored-Detection** |
|
|
|
> **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. |
|
|
|
```py |
|
Classification Report: |
|
precision recall f1-score support |
|
|
|
B & W 0.9982 0.9996 0.9989 5000 |
|
Colored 0.9996 0.9982 0.9989 5000 |
|
|
|
accuracy 0.9989 10000 |
|
macro avg 0.9989 0.9989 0.9989 10000 |
|
weighted avg 0.9989 0.9989 0.9989 10000 |
|
``` |
|
|
|
 |
|
|
|
--- |
|
|
|
The model categorizes images into 2 classes: |
|
|
|
``` |
|
Class 0: "B & W" |
|
Class 1: "Colored" |
|
``` |
|
|
|
--- |
|
|
|
## **Install dependencies** |
|
|
|
```python |
|
!pip install -q transformers torch pillow gradio |
|
``` |
|
|
|
--- |
|
|
|
## **Inference Code** |
|
|
|
```python |
|
import gradio as gr |
|
from transformers import AutoImageProcessor, SiglipForImageClassification |
|
from PIL import Image |
|
import torch |
|
|
|
# Load model and processor |
|
model_name = "prithivMLmods/BnW-vs-Colored-Detection" # Updated model name |
|
model = SiglipForImageClassification.from_pretrained(model_name) |
|
processor = AutoImageProcessor.from_pretrained(model_name) |
|
|
|
def classify_bw_colored(image): |
|
"""Predicts if an image is Black & White or Colored.""" |
|
image = Image.fromarray(image).convert("RGB") |
|
inputs = processor(images=image, return_tensors="pt") |
|
|
|
with torch.no_grad(): |
|
outputs = model(**inputs) |
|
logits = outputs.logits |
|
probs = torch.nn.functional.softmax(logits, dim=1).squeeze().tolist() |
|
|
|
labels = { |
|
"0": "B & W", "1": "Colored" |
|
} |
|
predictions = {labels[str(i)]: round(probs[i], 3) for i in range(len(probs))} |
|
|
|
return predictions |
|
|
|
# Create Gradio interface |
|
iface = gr.Interface( |
|
fn=classify_bw_colored, |
|
inputs=gr.Image(type="numpy"), |
|
outputs=gr.Label(label="Prediction Scores"), |
|
title="BnW vs Colored Detection", |
|
description="Upload an image to detect if it is Black & White or Colored." |
|
) |
|
|
|
if __name__ == "__main__": |
|
iface.launch() |
|
``` |
|
|
|
--- |
|
|
|
## **Intended Use:** |
|
|
|
The **BnW-vs-Colored-Detection** model is designed to classify images by color mode. Potential use cases include: |
|
|
|
- **Archive Organization:** Separate historical B&W images from modern colored ones. |
|
- **Data Filtering:** Preprocess image datasets by removing or labeling specific types. |
|
- **Digital Restoration:** Assist in determining candidates for colorization. |
|
- **Search & Categorization:** Enable efficient tagging and filtering in image libraries. |