Model Fine Tuning
The Smart City Blueprint uses two classes of models: computer vision models for object detection based on RT-DETR and Mask Grounding DINO, and vision language models (VLMs) based on NVIDIA Cosmos3 Nano Reasoner. Usage of these models is described in Blueprint Deep Dive.
You can fine tune the CV model to specialize detection accuracy for particular object classes or traffic scenarios. This page covers that end to end: training, evaluation, ONNX export, TensorRT conversion, deployment into the blueprint, acceptance criteria, and rollback.
CV model fine tuning
Fine-tuning TrafficCamNet Transformer Lite with TAO RT-DETR
The TrafficCamNet Transformer Lite model is based on the RT-DETR (Real-Time DEtection TRansformer) architecture and can be fine-tuned using NVIDIA TAO Toolkit to improve detection accuracy for specific traffic scenarios or new object classes.
Prerequisites
-
NVIDIA TAO Toolkit: Install TAO Toolkit following the official documentation.
-
Dataset: Prepare your dataset in COCO format with:
- Directory of training/validation images
- Annotation files in COCO JSON format
- Class mapping file (
labels.txt)
-
NGC CLI: Install NGC CLI following the NGC CLI documentation.
-
Base Model: Download the TrafficCamNet Transformer Lite pretrained model from the TAO Model Zoo using the NGC CLI.
Dataset Preparation
Organize your dataset in the following structure:
The annotations should follow COCO format with bounding boxes for objects like vehicles, pedestrians, and cyclists.
Creating the Experiment Spec File
Create a YAML specification file (e.g., rtdetr_trafficcam_finetune.yaml) with the following configuration:
Running Fine-Tuning
Execute the training command:
The training process will:
- Load the pretrained TrafficCamNet Transformer Lite weights
- Fine-tune on your custom dataset
- Save checkpoints every 5 epochs
- Run validation every 5 epochs
Resuming Training
If training is interrupted, resume from a checkpoint:
Evaluating the Fine-Tuned Model
After training, evaluate the model on your validation set:
This will output mAP (mean Average Precision) and per-class detection metrics.
Exporting for Deployment
Export the fine-tuned model to ONNX format for deployment:
The exported ONNX model can then be converted to TensorRT for optimized inference in production environments.
Fine-Tuning Tips
- Learning Rate: Start with a lower learning rate (0.0001) when fine-tuning from a pretrained model
- Data Augmentation: Adjust
distortion_probandiou_crop_probbased on your dataset characteristics - Epochs: Monitor validation mAP; typically 30-50 epochs are sufficient for fine-tuning
- Backbone Freezing: Set
train_backbone: falseto freeze backbone weights if you have limited data - Multi-GPU Training: Increase
num_gpusand adjustbatch_sizeproportionally for faster training
For more detailed information on RT-DETR configuration options, refer to the TAO RT-DETR documentation.