Layer Freezing and Transformer-Based Data Curation for Enhanced Transfer Learning in YOLO Architectures
Abstract
The You Only Look Once (YOLO) architecture has revolutionized real-time object detection by performing detection, localization, and classification in a single forward pass. However, balancing detection accuracy with computational efficiency remains a critical challenge, particularly for deployment in resource-constrained environments such as edge devices and UAV-based monitoring systems. This research presents a comprehensive analysis of layer freezing strategies for transfer learning in modern YOLO architectures, systematically investigating how selective parameter freezing affects both performance and computational requirements. We evaluate multiple freezing configurations across YOLOv8 and YOLOv10 variants (nano, small, medium, large) on four challenging datasets representing critical infrastructure monitoring applications: InsPLAD-det, Electric Substation, Common-VALID, and Bird's Nest. Our methodology incorporates gradient behavior analysis through L2 norm monitoring and visual explanations via Gradient-weighted Class Activation Mapping (GradCAM) to provide deeper insights into training dynamics under different freezing strategies. Results demonstrate that strategic layer freezing—particularly freezing the first 4 blocks or the complete backbone—achieves substantial computational savings while maintaining competitive detection accuracy. The optimal configurations reduce GPU memory consumption by up to 28% compared to full fine-tuning, while in several cases achieving superior mAP@50 scores (e.g., our YOLOv10-small with 4-block freezing achieved 0.84 vs 0.81 for fine-tuning on the InsPLAD-det dataset). Gradient analysis reveals distinct convergence patterns across freezing strategies, with backbone-frozen models exhibiting stable learning dynamics while preserving essential feature extraction capabilities. These findings provide actionable guidelines for deploying efficient YOLO models in resource-limited scenarios, demonstrating that selective layer freezing represents a viable alternative to full fine-tuning for transfer learning in object detection tasks.
Create a conda environment from the provided environment file:
conda env create -f environment.yml
Activate the conda environment:
conda activate enhanced-tl
After completing these steps, the required dependencies will be installed, and you can start training your models.
Usage
To display the help message and see all available options, run the following command:
python3 main.py --help
Example Output
When you run the help command, you will see an output like this:
console
1usage: main.py [-h] [--dataset DATASET_NAME] [--epochs EPOCHS] [--batch BATCH] [--imgsz IMGSZ]
2 [--patience PATIENCE] [--cache CACHE] [--pretrained] [--cos_lr] [--profile] [--plots] [--resume]
3 [--model MODEL_NAME] [--run RUN_NAME]
45options:
6 -h, --help show this help message and exit
7 --dataset DATASET_NAME
8 Dataset name to be used
9 --epochs EPOCHS Number of epochs for training
10 --batch BATCH Batch size
11 --imgsz IMGSZ Image size for training
12 --patience PATIENCE Early stopping patience
13 --cache CACHE Caching mechanism to use
14 --pretrained Use pretrained weights
15 --cos_lr Use cosine learning rate schedule
16 --profile Enable training profiling
17 --plots Generate training plots
18 --resume Resume training from a checkpoint
19 --model MODEL_NAME
20 Name of the YOLO model to use
21 --run RUN_NAME
22 Name of the run configuration
23