Introduction
Augmentation creates new versions of images by changing them slightly. This helps the model learn better by seeing more varied examples without needing more real pictures.
augmented_image = augmentation_function(original_image) # Example augmentations: # rotated_image = rotate(original_image, angle) # flipped_image = flip(original_image, direction) # bright_image = change_brightness(original_image, factor)
rotated_image = rotate(original_image, 15)flipped_image = flip(original_image, 'horizontal')bright_image = change_brightness(original_image, 1.2)augmented_images = [rotate(img, angle) for angle in [0, 90, 180, 270]]
import numpy as np import cv2 # Create a simple black square image original_image = np.zeros((100, 100, 3), dtype=np.uint8) cv2.rectangle(original_image, (30, 30), (70, 70), (255, 255, 255), -1) # Define augmentation functions def rotate(image, angle): center = (image.shape[1] // 2, image.shape[0] // 2) matrix = cv2.getRotationMatrix2D(center, angle, 1.0) rotated = cv2.warpAffine(image, matrix, (image.shape[1], image.shape[0])) return rotated def flip(image, direction): if direction == 'horizontal': return cv2.flip(image, 1) elif direction == 'vertical': return cv2.flip(image, 0) else: return image # Apply augmentations rotated_90 = rotate(original_image, 90) flipped_h = flip(original_image, 'horizontal') # Count total images original_count = 1 augmented_count = 2 print(f"Original images: {original_count}") print(f"Augmented images: {augmented_count}") print(f"Total training images: {original_count + augmented_count}")
from torchvision import transforms
transform = transforms.Compose([
transforms.RandomRotation(30),
transforms.RandomFlip(horizontal=true)
])Pass the test and this pattern moves unknown