microsoft/cats_vs_dogs
Viewer • Updated • 23.4k • 6.22k • 63
How to use nipunsgeeth/cats-vs-dogs-cnn with Keras:
# Available backend options are: "jax", "torch", "tensorflow".
import os
os.environ["KERAS_BACKEND"] = "jax"
import keras
model = keras.saving.load_model("hf://nipunsgeeth/cats-vs-dogs-cnn")
# Cats vs Dogs: CNN / Transfer‑Learning Model
This repository contains a convolutional neural network model trained to classify images of cats and dogs. The model was built using TensorFlow / Keras, trained on the `cats_vs_dogs` dataset, and designed for binary image classification.
## ✅ Model Details
- **Model type:** CNN (Transfer learning + custom head)
- **Input shape:** 160 × 160 × 3 (RGB image)
- **Output:** Single sigmoid output — probability that the image is a *dog*.
- **Training data:** cats_vs_dogs (loaded via `tensorflow_datasets`)
- **Preprocessing:** Images resized to 160×160, pixel values normalized (0–1)
- **Training & validation split:** 80% train / 20% validation
- **Library:** TensorFlow / Keras
## 🎯 Intended use
Use this model to classify images into two categories: **cat** or **dog**. You can use it for:
- Quick inference on image files
- As a baseline or demo for image classification tasks
- Educational purposes — to understand how CNN + transfer learning works
## ⚠️ Limitations
- The model performs reasonably but is **not state-of-the-art**; it may misclassify images with unusual angles, background clutter, or partial visibility.
- Because the dataset used has limited diversity, the model might be biased toward “typical” cat/dog images (good lighting, clear view). Use caution if applying to real-world images.
- **Not recommended for critical use** (e.g., medical, legal, safety-critical systems) — this is an example model.
## 🧰 How to Use (Inference Example)
```python
import tensorflow as tf
import numpy as np
from tensorflow.keras.preprocessing import image
# Load model
model = tf.keras.models.load_model("path/to/downloaded_model/")
# Load and preprocess image
img = image.load_img("path/to/your_image.jpg", target_size=(160,160))
img = image.img_to_array(img) / 255.0
img = np.expand_dims(img, axis=0)
# Predict
prob = model.predict(img)[0][0]
if prob >= 0.5:
print("Dog 🐶 — probability:", prob)
else:
print("Cat 🐱 — probability:", 1-prob)
saved_model/ or .keras / .h5 — the trained model filesexample_usage.py — a script to load the model and run predictions| Metric | Value |
|---|---|
| Validation Accuracy (after fine‑tuning) | ~ 0.5098 |
| Loss (binary cross‑entropy) | …0.6931 |
(If you trained longer / fine‑tuned — update these accordingly.)
If you want to improve this model:
Feel free to fork the repository, retrain, and open a pull request.