Transfer Learning:

  • Fine-tuning a Pretrained Model: Use models like VGG16 or ResNet50 pre-trained on ImageNet and fine-tune for a specific task, such as custom image classification.
pythonCopy codefrom tensorflow.keras.applications import VGG16
from tensorflow.keras import layers, models

# Load VGG16 without the top layer
base_model = VGG16(weights='imagenet', include_top=False, input_shape=(150, 150, 3))

# Freeze the base model
base_model.trainable = False

# Add custom layers
model = models.Sequential([
    base_model,
    layers.Flatten(),
    layers.Dense(256, activation='relu'),
    layers.Dense(1, activation='sigmoid')
])

# Compile and train the model
model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *