This repository contains two Jupyter notebooks for augmenting cucumber image datasets using classical data augmentation techniques and generative AI with StyleGAN2-ADA.
The project provides two different approaches to generate additional training data from cucumber images:
- Classical Data Augmentation: Uses traditional image transformation techniques
- Generative Augmentation: Uses StyleGAN2-ADA to generate synthetic cucumber images
- Python 3.7 or higher
- Jupyter Notebook or JupyterLab
- CUDA-compatible GPU (recommended for StyleGAN2-ADA)
Install the required dependencies:
pip install jupyter numpy pandas opencv-python albumentations==1.4.0For StyleGAN2-ADA notebook, additional requirements will be installed automatically within the notebook:
pip install torch torchvision ninjaThe notebooks expect the following dataset structure:
data_cucumber_images_jpg/
class1/
image1.jpg
image2.jpg
...
class2/
image1.jpg
...
File: dataset-classical-augmentation.ipynb
This notebook applies traditional image augmentation techniques including:
- Horizontal and vertical flips
- Random rotations
- Brightness and contrast adjustments
- Color transformations (Hue, Saturation, Value)
- Gaussian blur and noise
Steps:
- Open the notebook:
jupyter notebook dataset-classical-augmentation.ipynb - Update the
DATA_ROOTvariable to point to your dataset location - Configure augmentation parameters (optional):
N_AUG_PER_IMAGE: Number of augmented images per original image (default: 3)
- Run all cells sequentially
- Output:
- Augmented images saved in organized folders by class
augmentation_log.csv: Traceability log of all generated imagescucumber_images_augmented_zip.zip: Compressed archive of augmented images
File: generative-dataset-stylegan2-ada.ipynb
This notebook trains a StyleGAN2-ADA model to generate synthetic cucumber images.
Steps:
- Open the notebook:
jupyter notebook generative-dataset-stylegan2-ada.ipynb - Update the
DATASET_NAMEandSUBFOLDERvariables to match your dataset location - Run all cells sequentially:
- Cell 1: Flattens dataset structure for StyleGAN2
- Cell 2: Resizes images to 128x128 pixels
- Cell 3: Installs StyleGAN2-ADA dependencies and clones repository
- Cell 4: Trains the model (adjustable parameters):
--batch: Batch size (default: 16)--kimg: Training duration in thousands of images (default: 200)--mirror: Enable horizontal mirroring augmentation
- Cell 5: Locates the trained model checkpoint
- Cell 6: Generates synthetic images using the trained model
Training Parameters:
- Default training: 200k images (~200 iterations)
- GPU memory required: ~8GB minimum
- Training time: Varies based on GPU (several hours)
Output:
- Trained model checkpoints in
/kaggle/working/sg2_runs - Generated synthetic images
- Training logs and metrics
Modify the transform pipeline in the notebook to adjust augmentation intensity:
transform = A.Compose([
A.HorizontalFlip(p=0.5), # 50% probability
A.VerticalFlip(p=0.3), # 30% probability
A.RandomRotate90(p=0.5),
A.RandomBrightnessContrast(p=0.7),
# Add or remove transformations as needed
])Adjust training parameters in Cell 4:
--batch=16 # Reduce if GPU memory is limited
--kimg=200 # Increase for longer training
--mirror=1 # Use horizontal mirroring (recommended)
--gpus=1 # Number of GPUs to useaugmentation_log.csv: Details of each generated imagecucumber_images_augmented_zip.zip: All augmented images compressed
- Model checkpoints:
network-snapshot-*.pkl - Generated images organized by class
- Training logs and statistics
- Both notebooks are designed to run on Kaggle or similar cloud platforms but can be adapted for local execution
- Update all file paths if running locally instead of on Kaggle
- The StyleGAN2-ADA notebook requires significant computational resources
- Generated images maintain the original class structure for easy integration into training pipelines
Out of Memory Errors (StyleGAN2-ADA):
- Reduce
--batchparameter - Use smaller image resolution (current: 128x128)
- Ensure GPU has at least 8GB VRAM
Import Errors:
- Ensure all dependencies are installed:
pip install -r requirements.txt - For albumentations, use version 1.4.0 specifically
Dataset Not Found:
- Verify the
DATA_ROOTordata_rootpaths are correct - Check that images are in JPG/JPEG/PNG format
- Ensure directory structure matches expected format