![dfgx.png](https://cdn-uploads.huggingface.co/production/uploads/65bb837dbfb878f46c77de4c/p9wGZsE5Jt0DrJ8oOJYQ1.png)

# **WBC-Type-Classifier**

> **WBC-Type-Classifier** 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 different types of white blood cells (WBCs) using the **SiglipForImageClassification** architecture.  

```py
Accuracy: 0.9891
F1 Score: 0.9893

Classification Report:
              precision    recall  f1-score   support

    basophil     0.9822    0.9959    0.9890      1218
  eosinophil     0.9994    0.9984    0.9989      3117
erythroblast     0.9835    0.9974    0.9904      1551
          ig     0.9787    0.9693    0.9740      2895
  lymphocyte     0.9893    0.9942    0.9918      1214
    monocyte     0.9852    0.9852    0.9852      1420
  neutrophil     0.9876    0.9838    0.9857      3329
    platelet     1.0000    0.9996    0.9998      2348

    accuracy                         0.9891     17092
   macro avg     0.9882    0.9905    0.9893     17092
weighted avg     0.9891    0.9891    0.9891     17092
```

![download.png](https://cdn-uploads.huggingface.co/production/uploads/65bb837dbfb878f46c77de4c/ohM3P0nwh1LxVr7VNuQz2.png)

The model categorizes images into eight classes:
- **Class 0:** "Basophil"
- **Class 1:** "Eosinophil"
- **Class 2:** "Erythroblast"
- **Class 3:** "IG"
- **Class 4:** "Lymphocyte"
- **Class 5:** "Monocyte"
- **Class 6:** "Neutrophil"
- **Class 7:** "Platelet"

# **Run with Transformers🤗**

```python
!pip install -q transformers torch pillow gradio
```

```python
import gradio as gr
from transformers import AutoImageProcessor
from transformers import SiglipForImageClassification
from transformers.image_utils import load_image
from PIL import Image
import torch

# Load model and processor
model_name = "prithivMLmods/WBC-Type-Classifier"
model = SiglipForImageClassification.from_pretrained(model_name)
processor = AutoImageProcessor.from_pretrained(model_name)

def wbc_classification(image):
    """Predicts WBC type for a given blood cell image."""
    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": "Basophil", "1": "Eosinophil", "2": "Erythroblast", "3": "IG", 
        "4": "Lymphocyte", "5": "Monocyte", "6": "Neutrophil", "7": "Platelet"
    }
    predictions = {labels[str(i)]: round(probs[i], 3) for i in range(len(probs))}
    
    return predictions

# Create Gradio interface
iface = gr.Interface(
    fn=wbc_classification,
    inputs=gr.Image(type="numpy"),
    outputs=gr.Label(label="Prediction Scores"),
    title="WBC Type Classification",
    description="Upload a blood cell image to classify its WBC type."
)

# Launch the app
if __name__ == "__main__":
    iface.launch()
```

# **Intended Use:**  

The **WBC-Type-Classifier** model is designed to classify different types of white blood cells from blood smear images. Potential use cases include:  

- **Medical Diagnostics:** Assisting pathologists in identifying different WBC types for diagnosis.
- **Hematology Research:** Supporting studies related to blood cell morphology and disease detection.
- **Automated Blood Analysis:** Enhancing automated diagnostic tools for rapid blood cell classification.
- **Educational Purposes:** Providing insights and training data for medical students and researchers.
basophil eosinophil erythroblast ig lymphocyte monocyte neutrophil platelet