CoolFace
Modelpublic

UsamaHF/Cat-dog-classification

sourceHugging Facemitupdated 1y agoView on Hugging Face
1likes18downloads
Model Card

๐Ÿฑ๐Ÿถ 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

FieldDetails
ArchitectureCNN (3 Conv layers + Dense + Dropout)
FrameworkTensorFlow / Keras
Input Shape224 ร— 224 ร— 3 (RGB)
Output2 classes: Cat (0), Dog (1)
Loss FunctionSparse Categorical Crossentropy
OptimizerAdam
Datasetmicrosoft/catsvsdogs (Hugging Face)
Training Size~18.7k images (80% split)
Validation~4.7k images (20% split)

๐Ÿงช Performance

MetricValue
Accuracy~95%
ConfidenceSoftmax 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")