UsamaHF's picture
Update README.md
034c630 verified
---
license: mit
datasets:
- microsoft/cats_vs_dogs
metrics:
- accuracy
tags:
- image-classification
- tensorflow
- cnn
- cats-vs-dogs
- computer-vision
---
# 🐱🐶 Cat vs Dog Classifier (TensorFlow CNN)
A Convolutional Neural Network (CNN) model trained to classify images of **cats** and **dogs** using the [microsoft/cats_vs_dogs](https://huggingface.co/datasets/microsoft/cats_vs_dogs) dataset. Built using TensorFlow and trained on a balanced dataset of 23,000+ images.
---
## 🧠 Model Details
| Field | Details |
|-------------------|------------------------------------------|
| **Architecture** | CNN (3 Conv layers + Dense + Dropout) |
| **Framework** | TensorFlow / Keras |
| **Input Shape** | 224 × 224 × 3 (RGB) |
| **Output** | 2 classes: `Cat (0)`, `Dog (1)` |
| **Loss Function** | Sparse Categorical Crossentropy |
| **Optimizer** | Adam |
| **Dataset** | microsoft/cats_vs_dogs (Hugging Face) |
| **Training Size** | ~18.7k images (80% split) |
| **Validation** | ~4.7k images (20% split) |
---
## 🧪 Performance
| Metric | Value |
|------------|----------|
| Accuracy | ~95% |
| Confidence | Softmax output used in predictions |
> Evaluation done using 20% validation split.
---
## 🔍 How to Use
```python
from huggingface_hub import from_pretrained_keras
import tensorflow as tf
import numpy as np
from PIL import Image
# Load the model
model = from_pretrained_keras("UsamaHF/Cat-dog-classification")
# Load and preprocess image
img = Image.open("example.jpg").resize((224, 224)).convert("RGB")
img_array = np.expand_dims(np.array(img).astype("float32") / 255.0, axis=0)
# Get inference function
infer = model.signatures["serving_default"]
# Predict
output = infer(tf.constant(img_array))
predictions = output["output_0"].numpy() # Replace "dense_1" if needed
predicted_class = np.argmax(predictions[0])
print("Predicted:", "Dog" if predicted_class == 1 else "Cat")