🐱🐢 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 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

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")
Downloads last month
11
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Dataset used to train UsamaHF/Cat-dog-classification