Model Pipeline - Fine-tuning approach
Fine-tuning is a way to teach a model by starting with a model already trained on a big dataset. We then adjust it a little bit with our own smaller dataset to make it work better for our specific task.
Fine-tuning is a way to teach a model by starting with a model already trained on a big dataset. We then adjust it a little bit with our own smaller dataset to make it work better for our specific task.
Loss 1.2 |************ 0.9 |********* 0.7 |******* 0.6 |****** 0.55|***** 0.52|**** 0.48|**** 0.45|*** 0.43|** 0.42|*
| Epoch | Loss ↓ | Accuracy ↑ | Observation |
|---|---|---|---|
| 1 | 1.2 | 0.55 | Initial training of last layers, loss high, accuracy moderate |
| 2 | 0.9 | 0.68 | Loss decreases, accuracy improves as model learns |
| 3 | 0.7 | 0.75 | Continued improvement, model starts to generalize |
| 4 | 0.6 | 0.80 | Loss decreases steadily, accuracy rises |
| 5 | 0.55 | 0.83 | Last layers trained well, ready to unfreeze base layers |
| 6 | 0.52 | 0.85 | Unfreeze some base layers, start fine-tuning with low learning rate |
| 7 | 0.48 | 0.87 | Fine-tuning improves feature extraction, accuracy rises |
| 8 | 0.45 | 0.89 | Model converges with better accuracy and lower loss |
| 9 | 0.43 | 0.90 | Stable training, no overfitting observed |
| 10 | 0.42 | 0.91 | Final fine-tuned model ready for prediction |
trainable = False freezes the layers.base_model.trainable = False uses correct syntax. Options A, B, and C are invalid methods/attributes or incorrect (e.g., trainable = True unfreezes layers).base_model = tf.keras.applications.MobileNetV2(input_shape=(224,224,3), include_top=False, pooling='avg') new_output = tf.keras.layers.Dense(10, activation='softmax')(base_model.output) model = tf.keras.Model(inputs=base_model.input, outputs=new_output) print(model.output_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=5)
base_model.trainable = True
model.fit(train_data, epochs=5, learning_rate=0.001)model.fit method does not accept learning_rate as an argument; it belongs to the optimizer.# Step 1: Freeze base model base_model.trainable = False # Step 2: Add new classifier layers # Step 3: Train new layers # Step 4: Unfreeze some base layers # Step 5: Continue training with low learning rate Which of these is the best practice for Step 5?
Pass the test and this pattern moves unknown