BrejBala commited on
Commit
117e18e
·
verified ·
1 Parent(s): 484a5dc

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +215 -3
README.md CHANGED
@@ -1,3 +1,215 @@
1
- ---
2
- license: mit
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: en
3
+ license: mit
4
+ library_name: tensorflow
5
+ pipeline_tag: image-classification
6
+ tags:
7
+ - tensorflow
8
+ - keras
9
+ - tensorflow-hub
10
+ - mobilenetv2
11
+ - transfer-learning
12
+ - computer-vision
13
+ - image-classification
14
+ - multi-class-classification
15
+ - dog-breed-classification
16
+ - kaggle-competition
17
+ metrics:
18
+ - accuracy
19
+ - log_loss
20
+ model-index:
21
+ - name: Dog Breed Classification (TF Hub MobileNetV2 + Dense)
22
+ results:
23
+ - task:
24
+ type: image-classification
25
+ name: Image Classification
26
+ dataset:
27
+ name: Kaggle Dog Breed Identification (labels.csv + train images)
28
+ type: image
29
+ metrics:
30
+ - name: Validation Accuracy (subset experiment)
31
+ type: accuracy
32
+ value: 0.7750
33
+ - name: Validation Loss (subset experiment)
34
+ type: loss
35
+ value: 0.8411
36
+ ---
37
+
38
+ # 🐶 Dog Breed Classification (TensorFlow Hub MobileNetV2)
39
+
40
+ This model predicts the **dog breed (120 classes)** from an input image using **transfer learning** with a pretrained **MobileNetV2** model from **TensorFlow Hub**, plus a custom dense softmax classifier head.
41
+
42
+ It is built as an end-to-end computer vision pipeline: data loading → preprocessing → batching with `tf.data` → training with callbacks → evaluation/visualization → saving/loading → Kaggle-style probabilistic submission generation.
43
+
44
+ ## Model Details
45
+
46
+ - Developed by: brej-29
47
+ - Model type: TensorFlow / Keras `Sequential`
48
+ - Base: TF Hub MobileNetV2 ImageNet classifier
49
+ - Head: `Dense(120, activation="softmax")`
50
+ - Task: Multi-class image classification (120 dog breeds)
51
+ - Output: Probability distribution over 120 breeds (softmax)
52
+ - Input: RGB image resized to 224×224, normalized to [0, 1]
53
+ - Training notebook: `DogBreedClassification.ipynb`
54
+ - Source repo: https://github.com/brej-29/Logicmojo-AIML-Assignments-DogBreedClassificationTensorFlow
55
+ - License: MIT
56
+
57
+ ## Intended Use
58
+
59
+ - Educational / portfolio demonstration of transfer learning + end-to-end deep learning workflow
60
+ - Baseline experiments for multi-class dog breed recognition
61
+ - Generating probabilistic predictions for Kaggle-style submissions
62
+
63
+ ### Out-of-scope / Not suitable for
64
+
65
+ - Safety-critical or production use without further validation, monitoring, and retraining
66
+ - Use on non-dog images or heavily out-of-distribution images (e.g., cartoons, low-light, extreme blur) without robustness testing
67
+
68
+ ## Training Data
69
+
70
+ - Dataset: Kaggle “Dog Breed Identification”
71
+ - Training images: 10,222
72
+ - Classes: 120 dog breeds
73
+ - Labels file: `labels.csv` (maps `id` → `breed`)
74
+
75
+ Note: Kaggle’s official competition metric is **log loss** (requires calibrated class probabilities). This project produces probabilistic outputs suitable for that metric, but offline log loss computation is not explicitly reported in the notebook.
76
+
77
+ ## Preprocessing
78
+
79
+ Image preprocessing applied during training/inference:
80
+
81
+ - Read JPG from filepath
82
+ - Decode to RGB tensor
83
+ - Convert dtype to float32 and normalize to [0, 1]
84
+ - Resize to **224×224**
85
+
86
+ Efficient input pipeline:
87
+
88
+ - Training batches use shuffling and `tf.data` batching
89
+ - Validation batches avoid shuffling
90
+ - Test batches contain filepaths only (no labels)
91
+
92
+ ## Label Encoding / Class Order (Important)
93
+
94
+ - Labels are one-hot encoded based on:
95
+ - `unique_breeds = np.unique(labels)` (alphabetical order by default for NumPy unique)
96
+ - The model’s output index `i` corresponds to `unique_breeds[i]`
97
+
98
+ To ensure correct decoding of predictions on the Hub, you should provide the class list (e.g., `class_names.json` or `unique_breeds.txt`) in the model repository.
99
+
100
+ ## Training Procedure
101
+
102
+ - Framework: TensorFlow 2.x / Keras
103
+ - Base model URL (TF Hub):
104
+ - `https://tfhub.dev/google/imagenet/mobilenet_v2_130_224/classification/4`
105
+ - Loss: `CategoricalCrossentropy`
106
+ - Optimizer: `Adam`
107
+ - Metrics: `accuracy`
108
+ - Callbacks:
109
+ - TensorBoard logging
110
+ - EarlyStopping
111
+ - Subset training monitors `val_accuracy` (patience=3)
112
+ - Full training (no validation set) monitors `accuracy` (patience=3)
113
+
114
+ ### Subset Experiment (for fast iteration)
115
+
116
+ - Subset size: 2,000 images
117
+ - Split: 80% train / 20% validation (`random_state=42`)
118
+ - Epochs configured: 100 (with EarlyStopping)
119
+
120
+ ### Full Training
121
+
122
+ - The notebook also trains on the full dataset to generate Kaggle-style predictions.
123
+ - Since the full run does not use a dedicated validation set, validation metrics are not reported for that phase.
124
+
125
+ ## Evaluation
126
+
127
+ Reported evaluation (subset experiment; validation split from first 2,000 images):
128
+
129
+ - Validation Accuracy: **0.7750**
130
+ - Validation Loss: **0.8411**
131
+
132
+ Important: This is a quick experiment metric and may not represent final performance on the full dataset or on real-world dog images.
133
+
134
+ ## How to Use
135
+
136
+ The recommended approach is:
137
+ 1) Download the saved model artifact from the Hub
138
+ 2) Apply the same preprocessing (resize 224×224, normalize)
139
+ 3) Run `model.predict()`
140
+ 4) Decode the top-k indices using the stored class list (same order as training)
141
+
142
+ Example (update filenames to match your uploaded artifacts):
143
+
144
+ import json
145
+ import numpy as np
146
+ import tensorflow as tf
147
+ import tensorflow_hub as hub
148
+ from huggingface_hub import hf_hub_download
149
+
150
+ repo_id = "YOUR_USERNAME/YOUR_MODEL_REPO"
151
+
152
+ # 1) Download model (example: H5)
153
+ model_path = hf_hub_download(repo_id=repo_id, filename="dog_breed_mobilenetv2.h5")
154
+ model = tf.keras.models.load_model(
155
+ model_path,
156
+ custom_objects={"KerasLayer": hub.KerasLayer},
157
+ compile=False
158
+ )
159
+
160
+ # 2) Download class names (recommended to upload alongside the model)
161
+ classes_path = hf_hub_download(repo_id=repo_id, filename="class_names.json")
162
+ class_names = json.load(open(classes_path, "r"))
163
+
164
+ # 3) Preprocess a single image
165
+ def preprocess_image(path, img_size=224):
166
+ img = tf.io.read_file(path)
167
+ img = tf.image.decode_jpeg(img, channels=3)
168
+ img = tf.image.convert_image_dtype(img, tf.float32)
169
+ img = tf.image.resize(img, [img_size, img_size])
170
+ return tf.expand_dims(img, axis=0) # add batch dim
171
+
172
+ x = preprocess_image("your_dog.jpg")
173
+ probs = model.predict(x)[0]
174
+
175
+ # 4) Top-5 predictions
176
+ top5 = probs.argsort()[-5:][::-1]
177
+ for idx in top5:
178
+ print(class_names[idx], float(probs[idx]))
179
+
180
+ If you uploaded a TensorFlow SavedModel folder instead of an `.h5` file, download the folder files and load with `tf.keras.models.load_model(...)` accordingly.
181
+
182
+ ## Input Requirements
183
+
184
+ - Input type: RGB images (JPG/PNG supported if decoded to RGB)
185
+ - Image size: **224×224**
186
+ - Value range: float32 normalized to **[0, 1]**
187
+ - Output decoding must use the same class order used during training (`np.unique(labels)` order)
188
+
189
+ ## Bias, Risks, and Limitations
190
+
191
+ - Dataset bias: model is trained on a specific Kaggle dataset; results may not generalize to all real-world photos
192
+ - Class ambiguity: many dog breeds look visually similar; mistakes are expected
193
+ - Out-of-distribution risk: performance may drop significantly on unusual lighting, occlusions, non-dog animals, mixed breeds, or stylized images
194
+ - Label-order dependency: wrong class mapping will produce incorrect breed names even if probabilities are correct
195
+
196
+ ## Environmental Impact
197
+
198
+ Transfer learning with MobileNetV2 is relatively compute-efficient compared to training a CNN from scratch. Training can be done on GPU for speed, but overall footprint is modest for a model of this size.
199
+
200
+ ## Technical Specifications
201
+
202
+ - Framework: TensorFlow 2.x / Keras
203
+ - Base model: TF Hub MobileNetV2 (ImageNet pretrained)
204
+ - Head: Dense softmax classifier (120 units)
205
+ - Task: image-classification
206
+ - Recommended runtime: CPU (inference) / GPU (training)
207
+
208
+ ## Model Card Authors
209
+
210
+ - BrejBala
211
+
212
+ ## Contact
213
+
214
+ For questions/feedback, please open an issue on the GitHub repository:
215
+ https://github.com/brej-29/Logicmojo-AIML-Assignments-DogBreedClassificationTensorFlow