Model Pipeline - Transfer learning for small datasets
This pipeline uses a pre-trained model to learn from a small dataset quickly and accurately. It reuses learned features from a large dataset and fine-tunes the model on new data.
This pipeline uses a pre-trained model to learn from a small dataset quickly and accurately. It reuses learned features from a large dataset and fine-tunes the model on new data.
Loss
1.2 |*
1.0 | *
0.8 | *
0.6 | *
0.4 | *
+---------
1 2 3 4 5
Epochs| Epoch | Loss ↓ | Accuracy ↑ | Observation |
|---|---|---|---|
| 1 | 1.20 | 0.45 | Model starts learning from small dataset |
| 2 | 0.85 | 0.65 | Loss decreases, accuracy improves |
| 3 | 0.60 | 0.78 | Model fine-tunes classification head well |
| 4 | 0.50 | 0.82 | Training stabilizes with good accuracy |
| 5 | 0.45 | 0.85 | Final epoch shows best performance |
trainable = False on the base model freezes all its layers.base_model.trainable = False is valid TensorFlow syntax to freeze layers.base_model.trainable = False -> Option Cimport tensorflow as tf base_model = tf.keras.applications.MobileNetV2(input_shape=(128,128,3), include_top=False, pooling='avg') base_model.trainable = False model = tf.keras.Sequential([ base_model, tf.keras.layers.Dense(10, activation='softmax') ]) model.build((None, 128, 128, 3)) predictions = model(tf.random.uniform((5, 128, 128, 3))) print(predictions.shape)
base_model = tf.keras.applications.ResNet50(weights='imagenet', include_top=False) base_model.trainable = False model = tf.keras.Sequential([ base_model, tf.keras.layers.Dense(5, activation='softmax') ]) model.compile(optimizer='adam', loss='sparse_categorical_crossentropy') model.fit(train_data, epochs=3)
Pass the test and this pattern moves unknown