microsoft/cats_vs_dogs
Viewer β’ Updated β’ 23.4k β’ 4.53k β’ 63
How to use UsamaHF/Cat-dog-classification with TF-Keras:
# Note: 'keras<3.x' or 'tf_keras' must be installed (legacy)
# See https://github.com/keras-team/tf-keras for more details.
from huggingface_hub import from_pretrained_keras
model = from_pretrained_keras("UsamaHF/Cat-dog-classification")
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.
| 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) |
| Metric | Value |
|---|---|
| Accuracy | ~95% |
| Confidence | Softmax output used in predictions |
Evaluation done using 20% validation split.
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")