Downloads · 30 days
9
9% of all-time downloads
sirunchained/cats-vs-dogs
cats-vs-dogs is a image classification model from sirunchained. Use it when you need a label for an image. It is set up for keras. The card lists the license as mit.
This model is a deep learning classifier capable of distinguishing between images of cats and dogs. It leverages the power of EfficientNetB0 for robust feature extraction and is fine-tuned for this binary classificati…
Downloads · 30 days
9
9% of all-time downloads
All-time downloads
102
Public
Repo size
102 MB
Likes
0
Public
Click a slice to open those files.
.keras50.8 MB · 100%
From the Hugging Face model README
This model is a deep learning classifier capable of distinguishing between images of cats and dogs. It leverages the power of EfficientNetB0 for robust feature extraction and is fine-tuned for this binary classification task.
cats_vs_dogs from tensorflow_datasets0.1.The model is built using a pre-trained EfficientNetB0 backbone (pre-trained on ImageNet) and custom classification layers:
EfficientNetB0 (without top layers, include_top=False)(150, 150, 3) (images are resized to this dimension)GlobalAveragePooling2D(): Reduces spatial dimensions of feature maps.Dense(units=100, activation="relu"): A fully connected layer with ReLU activation.Dense(units=1, activation="sigmoid"): Output layer for binary classification, producing a probability between 0 and 1.The model was evaluated on a test set of 4653 images. Here are the key metrics:
Classification Report:
precision recall f1-score support
0 0.99 0.99 0.99 2273
1 0.99 0.99 0.99 2380
accuracy 0.99 4653
macro avg 0.99 0.99 0.99 4653
weighted avg 0.99 0.99 0.99 4653
You can use this model for image classification. Here's a Python snippet using TensorFlow and the huggingface_hub library:
import tensorflow as tf
from PIL import Image
from huggingface_hub import hf_hub_download
import numpy as np
# Download the model from Hugging Face Hub
model_path = hf_hub_download(
repo_id="sirunchained/cats-vs-dogs",
filename="cats-vs-dogs.keras"
)
# Load the model
model = tf.keras.models.load_model(model_path)
classes = ["Cat", "Dog"]
IMG_SIZE = 150
def predict_image(image_path):
img = Image.open(image_path).resize((IMG_SIZE, IMG_SIZE))
img_array = np.array(img)
img_array = tf.expand_dims(img_array, axis=0)
img_array = tf.cast(img_array, tf.float32)
predictions = model.predict(img_array)
predicted_confidence = predictions[0][0] # Since it's a binary classifier with sigmoid output
if predicted_confidence >= 0.5:
predicted_class = "Dog"
confidence = predicted_confidence
else:
predicted_class = "Cat"
confidence = 1 - predicted_confidence
return predicted_class, confidence
# Example usage:
# predicted_class, confidence = predict_image("path/to/your/image.jpg")
# print(f"Predicted: {predicted_class} with confidence: {confidence:.2f}")
You can interact with a live demo of this model through Gradio: