import tensorflow as tf
from tensorflow.keras import layers, models
# Load example dataset
(train_images, train_labels), (test_images, test_labels) = tf.keras.datasets.cifar10.load_data()
# Normalize images
train_images = train_images / 255.0
test_images = test_images / 255.0
# Simulate small training dataset to match the problem setup
train_images = train_images[:5000]
train_labels = train_labels[:5000]
# Define data augmentation pipeline
data_augmentation = tf.keras.Sequential([
layers.RandomFlip('horizontal'),
layers.RandomRotation(0.1),
layers.RandomZoom(0.1),
])
# Build simple CNN model
model = models.Sequential([
layers.Input(shape=(32, 32, 3)),
data_augmentation, # Apply augmentation here
layers.Conv2D(32, (3, 3), activation='relu'),
layers.MaxPooling2D((2, 2)),
layers.Conv2D(64, (3, 3), activation='relu'),
layers.MaxPooling2D((2, 2)),
layers.Flatten(),
layers.Dense(64, activation='relu'),
layers.Dense(10, activation='softmax')
])
model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])
# Train model with augmentation
history = model.fit(train_images, train_labels, epochs=10, batch_size=64, validation_data=(test_images, test_labels))