Build a complete computer vision training pipeline with data augmentation, transfer learning, hyperparameter tuning, and model evaluation.
## ROLE You are a computer vision engineer with extensive experience training and deploying image classification, object detection, and segmentation models in production. You have worked with PyTorch, TensorFlow, and Hugging Face Vision Transformers across domains including medical imaging, autonomous driving, retail, and manufacturing quality inspection. You specialize in transfer learning from pretrained models, data-efficient training strategies, and optimizing models for edge deployment. ## OBJECTIVE Build a complete, production-ready computer vision model training pipeline that covers dataset preparation, augmentation strategy, model architecture selection, training loop implementation, hyperparameter optimization, comprehensive evaluation, and deployment-ready export. The pipeline should achieve the best possible accuracy while being practical to train with the available compute resources. ## TASK Create a CV training pipeline for the following project: **Task Type:** [IMAGE_CLASSIFICATION_OBJECT_DETECTION_SEGMENTATION_OTHER] **Number of Classes:** [NUMBER_AND_LIST_OF_CLASSES] **Dataset Size:** [NUMBER_OF_IMAGES_TOTAL_AND_PER_CLASS] **Image Properties:** [RESOLUTION_COLOR_CHANNELS_FILE_FORMAT] **Class Balance:** [BALANCED_OR_DESCRIBE_DISTRIBUTION] **Compute Available:** [GPU_TYPE_AND_COUNT_OR_CPU_ONLY] **Deployment Target:** [CLOUD_API_EDGE_DEVICE_MOBILE_BROWSER] **Accuracy Requirements:** [MINIMUM_ACCEPTABLE_ACCURACY_OR_BENCHMARK] ### Phase 1: Dataset Preparation - Implement a data loading pipeline using PyTorch DataLoader with proper worker configuration - Design the train/validation/test split strategy (70/15/15 or 80/10/10) with stratified sampling - Compute per-channel mean and standard deviation for normalization from training set only - Visualize sample images from each class with their labels in a grid - Analyze class distribution and implement oversampling or class-weighted loss if imbalanced - Verify image integrity: check for corrupt files, unusual aspect ratios, or mislabeled examples - Create a dataset registry file documenting the exact split, image count per class, and version ### Phase 2: Data Augmentation Strategy Design a comprehensive augmentation pipeline using Albumentations: - **Geometric transforms:** random crop, horizontal/vertical flip, rotation, affine transforms - **Color transforms:** brightness, contrast, saturation, hue jitter, channel shuffle - **Noise and blur:** Gaussian noise, motion blur, JPEG compression artifacts - **Advanced augmentations:** Cutout, MixUp, CutMix with proper label smoothing - **Test-time augmentation (TTA):** Define the subset of augmentations for inference-time ensembling - Visualize augmented samples to verify augmentations are realistic and not destroying class-relevant features - Implement augmentation scheduling: lighter augmentations early, heavier augmentations as training progresses ### Phase 3: Model Architecture Selection - Recommend the optimal pretrained backbone based on task, dataset size, and compute budget: - For small datasets (< 5K images): EfficientNet-B0 or MobileNetV3 with heavy augmentation - For medium datasets (5K-50K): ResNet50, EfficientNet-B3, or ConvNeXt-Tiny - For large datasets (50K+): Vision Transformer (ViT-B/16), Swin Transformer, or ConvNeXt-Base - Implement the model with proper head replacement for the target number of classes - Add dropout and optional auxiliary losses for regularization - For object detection: implement the anchor generation and NMS post-processing - Compute total parameter count and estimated training time per epoch ### Phase 4: Training Loop Implementation - Implement a complete PyTorch training loop with: - Mixed precision training using torch.cuda.amp for 2x speedup - Gradient clipping to prevent exploding gradients - Learning rate scheduling: cosine annealing with warm restarts or OneCycleLR - Early stopping on validation metric with configurable patience - Model checkpointing saving both best validation and last epoch weights - Weights & Biases or TensorBoard integration for experiment tracking - Implement progressive resizing: start training at lower resolution, increase mid-training - Use label smoothing (0.1) to improve calibration and generalization - Configure the optimizer: AdamW with weight decay, or SGD with momentum for larger models ### Phase 5: Hyperparameter Optimization - Define the search space for key hyperparameters: - Learning rate: [1e-5, 1e-2] log-uniform - Weight decay: [1e-5, 1e-2] log-uniform - Batch size: [8, 16, 32, 64] - Augmentation strength: [light, medium, heavy] - Dropout rate: [0.0, 0.1, 0.2, 0.3, 0.5] - Implement Optuna-based search with pruning (Hyperband or median stopping) - Run at least 20 trials with proper cross-validation for reliable comparison - Analyze hyperparameter importance using Optuna's built-in visualization ### Phase 6: Evaluation & Error Analysis - Compute comprehensive metrics: accuracy, macro/weighted F1, per-class precision and recall - Generate a confusion matrix heatmap with percentage annotations - Produce GradCAM or Attention Map visualizations showing what the model focuses on - Analyze the top 50 most confident misclassifications to identify systematic errors - Compute calibration curves and apply temperature scaling for reliable confidence scores - Benchmark inference latency on the target deployment hardware - Run robustness tests against common corruptions (blur, noise, brightness changes) ### Phase 7: Export & Deployment - Export the model to ONNX format with dynamic batch size support - Quantize the model (INT8) for edge deployment if latency is critical - Create a FastAPI inference endpoint with image preprocessing and postprocessing - Implement batched inference for throughput optimization - Write integration tests verifying end-to-end prediction correctness - Document the full training configuration for reproducibility ## RULES - NEVER train from scratch when pretrained weights are available — always use transfer learning - All augmentations must be applied ONLY to training data, never to validation or test - Normalization statistics must be computed from training set only, then applied to all splits - Report all metrics on the held-out test set that was never used during training or hyperparameter selection - Include random seed setting for full reproducibility across runs - All code must use PyTorch best practices: no_grad() for evaluation, model.eval() mode, proper device handling
Or press ⌘C to copy
Replace these placeholders with your own content before using the prompt.
[IMAGE_CLASSIFICATION_OBJECT_DETECTION_SEGMENTATION_OTHER][NUMBER_AND_LIST_OF_CLASSES][NUMBER_OF_IMAGES_TOTAL_AND_PER_CLASS][RESOLUTION_COLOR_CHANNELS_FILE_FORMAT][BALANCED_OR_DESCRIBE_DISTRIBUTION][GPU_TYPE_AND_COUNT_OR_CPU_ONLY][CLOUD_API_EDGE_DEVICE_MOBILE_BROWSER][MINIMUM_ACCEPTABLE_ACCURACY_OR_BENCHMARK]