Views
No views yet
1
2# Cats vs Dogs: CNN / Transfer‑Learning Model
3
4This 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.
5
6## ✅ Model Details
7
8- **Model type:** CNN (Transfer learning + custom head)
9- **Input shape:** 160 × 160 × 3 (RGB image)
10- **Output:** Single sigmoid output — probability that the image is a *dog*.
11- **Training data:** cats_vs_dogs (loaded via `tensorflow_datasets`)
12- **Preprocessing:** Images resized to 160×160, pixel values normalized (0–1)
13- **Training & validation split:** 80% train / 20% validation
14- **Library:** TensorFlow / Keras
15
16## 🎯 Intended use
17
18Use this model to classify images into two categories: **cat** or **dog**. You can use it for:
19
20- Quick inference on image files
21- As a baseline or demo for image classification tasks
22- Educational purposes — to understand how CNN + transfer learning works
23
24## ⚠️ Limitations
25
26- The model performs reasonably but is **not state-of-the-art**; it may misclassify images with unusual angles, background clutter, or partial visibility.
27- 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.
28- **Not recommended for critical use** (e.g., medical, legal, safety-critical systems) — this is an example model.
29
30## 🧰 How to Use (Inference Example)
31
32```python
33import tensorflow as tf
34import numpy as np
35from tensorflow.keras.preprocessing import image
36
37# Load model
38model = tf.keras.models.load_model("path/to/downloaded_model/")
39
40# Load and preprocess image
41img = image.load_img("path/to/your_image.jpg", target_size=(160,160))
42img = image.img_to_array(img) / 255.0
43img = np.expand_dims(img, axis=0)
44
45# Predict
46prob = model.predict(img)[0][0]
47if prob >= 0.5:
48 print("Dog 🐶 — probability:", prob)
49else:
50 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 |