TrafficCamNet Transformer Lite Fine-Tuning: Good Validation mAP but No Detection of Old or New Classes
Description
I am trying to fine-tune the NVIDIA TrafficCamNet Transformer Lite [Trainable ResNet50_v2.0] model using my own custom dataset.
The main issue is that the original pretrained TrafficCamNet model can detect cars correctly before fine-tuning, but after fine-tuning, the resulting model does not detect cars anymore.
It also does not detect the new classes that I added to the training dataset, such as truck, excavator, bull_dozer, and grader.
This is unexpected because the fine-tuned model achieves reasonably good validation metrics.
I would like to understand whether this is related to the pretrained weights, class mapping, detection head, checkpoint loading, or the fine-tuning procedure.
1. Model
I am using:
TrafficCamNet Transformer Lite [Trainable ResNet50_v2.0]
The pretrained model is:
resnet50_trafficcamnet_rtdetr.pth
The pretrained model is used in my training configuration:
train:
pretrained_model_path: /workspace/trafficcamnet_tao/abhay/pretrained/trafficcamnet_transformer_lite_vtrainable_resnet50_v2.0/resnet50_trafficcamnet_rtdetr.pth
The model configuration contains:
model:
backbone: resnet_50
train_backbone: true
num_queries: 300
num_select: 300
num_feature_levels: 3
2. Custom Dataset
I created a new dataset for fine-tuning.
Dataset size:
| Dataset | Images |
|---|---|
| Train | 8,241 |
| Validation | 966 |
| Test | 478 |
| Total | 9,685 |
Class-wise image distribution:
| Class | Number of Images |
|---|---|
| car | 1,035 |
| person | 736 |
| truck | 3,256 |
| bull_dozer | 1,356 |
| excavator | 744 |
| front_end_loader | 1,098 |
| grader | 1,460 |
| road_sign | 0 |
| bicycle | 0 |
road_sign and bicycle currently have zero images in the dataset.
The model configuration contains:
num_classes: 9
3. labels.txt
My class mapping file is located at:
/home/inthings/adin/july/trafficcamnet_tao/abhay/specs/labels.txt
The contents are:
car
road_sign
person
bicycle
truck
bull_dozer
excavator
front_end_loader
grader
Therefore, the class order in labels.txt is:
0 → car
1 → road_sign
2 → person
3 → bicycle
4 → truck
5 → bull_dozer
6 → excavator
7 → front_end_loader
8 → grader
The inference configuration uses this file:
infer_data_sources:
classmap: /workspace/trafficcamnet_tao/abhay/specs/labels.txt
I would particularly like to confirm whether this class order must exactly match the category IDs in the COCO annotation JSON.
4. Training Configuration
The relevant part of my training configuration is:
model:
pretrained_backbone_path: null
backbone: resnet_50
train_backbone: true
load_teacher_enc_dec: false
num_queries: 300
num_select: 300
num_feature_levels: 3
hidden_dim: 256
nheads: 8
enc_layers: 1
dec_layers: 6
dn_number: 100
dataset:
train_data_sources:
- image_dir: /workspace/trafficcamnet_tao/abhay/retrain_final/train
json_file: /workspace/trafficcamnet_tao/abhay/retrain_final/train/_annotations_clean.coco.json
val_data_sources:
image_dir: /workspace/trafficcamnet_tao/abhay/retrain_final/valid
json_file: /workspace/trafficcamnet_tao/abhay/retrain_final/valid/_annotations_clean.coco.json
test_data_sources:
image_dir: /workspace/trafficcamnet_tao/abhay/retrain_final/test
json_file: /workspace/trafficcamnet_tao/abhay/retrain_final/test/_annotations_clean.coco.json
num_classes: 9
Training configuration:
train:
num_gpus: 1
gpu_ids:
- 0
num_epochs: 72
checkpoint_interval: 1
validation_interval: 4
pretrained_model_path: /workspace/trafficcamnet_tao/abhay/pretrained/trafficcamnet_transformer_lite_vtrainable_resnet50_v2.0/resnet50_trafficcamnet_rtdetr.pth
freeze: []
optim:
optimizer: AdamW
lr: 0.00005
lr_backbone: 0.000005
weight_decay: 0.0001
lr_scheduler: MultiStep
lr_steps:
- 48
- 64
precision: fp32
The backbone is being trained:
train_backbone: true
and I am not freezing any layers:
freeze: []
5. Training Results
The best checkpoint I obtained was:
model_epoch_063.pth
The validation results were:
Validation mAP:
0.7200985566483297
Validation mAP50:
0.9106943208778269
Validation loss:
1.0558826923370361
Training loss:
10.628334999084473
So the validation results appear reasonably good:
mAP = 0.72
mAP50 = 0.91
6. Evaluation and Inference Configuration
I am evaluating the same checkpoint:
evaluate:
checkpoint: /workspace/trafficcamnet_tao/testing63/model_epoch_063.pth
results_dir: /workspace/trafficcamnet_tao/testing63/eval_epoch063
input_width: 960
input_height: 544
conf_threshold: 0.0
For inference:
inference:
checkpoint: /workspace/trafficcamnet_tao/testing63/model_epoch_063.pth
results_dir: /workspace/trafficcamnet_tao/testing63/inference_test_epoch063_lowconf
conf_threshold: 0.25
input_width: 960
input_height: 544
The inference dataset uses:
infer_data_sources:
image_dir:
- /workspace/trafficcamnet_tao/abhay/test_epoch063
classmap: /workspace/trafficcamnet_tao/abhay/specs/labels.txt
batch_size: 1
workers: 2
num_classes: 9
7. Inference Command
I am running inference using:
tao model rtdetr inference \
-e /workspace/trafficcamnet_tao/abhay/specs/full_spec.yaml \
inference.checkpoint=/workspace/trafficcamnet_tao/testing63/model_epoch_063.pth \
results_dir=/workspace/trafficcamnet_tao/testing63/inference_retrain_final_epoch063
The inference is therefore using the same checkpoint:
model_epoch_063.pth
that I evaluated.
8. Actual Problem
The original pretrained TrafficCamNet model works correctly for car detection.
Before fine-tuning
Original pretrained TrafficCamNet
↓
Input image
↓
Car detected correctly
After fine-tuning
Fine-tuned TrafficCamNet
↓
Same/similar input image
↓
Car NOT detected
The new classes are also not detected:
truck → NOT detected
excavator → NOT detected
bull_dozer → NOT detected
grader → NOT detected
front_end_loader → NOT detected
person → NOT detected
So the problem is not only that the original car class is lost.
The newly trained classes are also not detected during inference.
9. Main Question About Pretrained Weights
My understanding is that during fine-tuning, the pretrained TrafficCamNet model’s learned weights and biases are used as the starting point, and then the model is further trained using my custom dataset.
I am using:
pretrained_model_path: /workspace/trafficcamnet_tao/abhay/pretrained/trafficcamnet_transformer_lite_vtrainable_resnet50_v2.0/resnet50_trafficcamnet_rtdetr.pth
However, after fine-tuning, I observe:
-
The original
carclass is no longer detected. -
The new classes are also not detected.
-
Validation mAP50 is
0.91.
I would like to understand exactly what happens to the pretrained weights during this fine-tuning process.
10. Questions for NVIDIA
Question 1 — Why does the old class stop working?
If the pretrained TrafficCamNet weights and biases are used as the starting point for fine-tuning, why does the fine-tuned model lose the ability to detect the original car class?
Is this expected when changing the model from the original classes to a custom 9-class dataset?
Question 2 — Why are the new classes also not detected?
If the model is trained using the new dataset containing:
car
road_sign
person
bicycle
truck
bull_dozer
excavator
front_end_loader
grader
why does the resulting model fail to detect both:
-
the original
carclass, and -
the newly trained classes?
What could cause this behavior?
Question 3 — What happens to the pretrained detection/classification head?
When I change the number of classes to:
num_classes: 9
what happens internally to the pretrained TrafficCamNet detection/classification head?
Are the original classification-head weights:
-
reused,
-
discarded,
-
reinitialized,
-
or partially reused?
Are the pretrained backbone weights retained while the classification head is newly initialized for 9 classes?
I would like to understand exactly which pretrained weights and biases are retained and which are newly initialized.
Question 4 — What is the correct way to train these 9 classes?
What is the recommended NVIDIA TAO procedure for fine-tuning TrafficCamNet Transformer Lite so that the final model correctly detects all 9 classes?
My expected classes are:
0 → car
1 → road_sign
2 → person
3 → bicycle
4 → truck
5 → bull_dozer
6 → excavator
7 → front_end_loader
8 → grader
What configuration should be used to correctly train and infer these 9 classes?
Question 5 — Does the class order matter?
My labels.txt contains:
car
road_sign
person
bicycle
truck
bull_dozer
excavator
front_end_loader
grader
Does this order need to exactly match the category IDs in the COCO annotation files?
Could an incorrect mapping between:
COCO category ID
↓
labels.txt
↓
model class index
↓
inference output
cause the model to appear as if it is not detecting the correct classes?
Question 6 — Should the original classes be included in the training data?
If my goal is to retain the pretrained model’s ability to detect cars while adding new classes, should I include enough examples of the original classes in the fine-tuning dataset?
For example, should I use a dataset containing:
Original classes + New classes
with sufficient training samples for each class?
Question 7 — Could catastrophic forgetting be happening?
Could this problem be caused by catastrophic forgetting?
The original pretrained TrafficCamNet model was trained on a much larger dataset, while my custom dataset contains only:
9,685 images
Could fine-tuning on this smaller/custom dataset cause the model to lose its original car-detection capability?
If yes, what is the recommended TAO approach to prevent this?
Would techniques such as:
-
freezing some layers,
-
reducing the learning rate,
-
knowledge distillation,
-
retaining some original training data,
-
or another fine-tuning strategy
be recommended?
Question 8 — Is my current training configuration correct?
I am currently using:
train_backbone: true
freeze: []
lr: 0.00005
lr_backbone: 0.000005
num_classes: 9
Is this an appropriate configuration for fine-tuning TrafficCamNet Transformer Lite with a new 9-class dataset?
Should I freeze the backbone or any other layers?
Question 9 — Why is validation good but inference fails?
How can the model achieve:
mAP = 0.72
mAP50 = 0.91
during validation but fail to produce detections during inference?
Could this indicate a problem with:
-
class mapping,
-
COCO category IDs,
-
labels.txt, -
num_classes, -
checkpoint loading,
-
preprocessing,
-
confidence threshold,
-
inference configuration,
-
or model export?
Question 10 — What is the correct solution?
Ultimately, I want one fine-tuned TrafficCamNet Transformer Lite model that correctly detects these 9 classes:
car
road_sign
person
bicycle
truck
bull_dozer
excavator
front_end_loader
grader
What is the recommended NVIDIA TAO workflow to achieve this while making use of the pretrained TrafficCamNet model?
In particular, I would like to understand why the fine-tuned model does not detect either the old class or the new classes, despite starting from the pretrained TrafficCamNet weights and achieving good validation metrics.
11. Expected Result
My expected result is:
Input image
↓
Fine-tuned TrafficCamNet Transformer Lite
↓
Correct detection
↓
car
person
truck
bull_dozer
excavator
front_end_loader
grader
road_sign
bicycle
The model should correctly detect whichever of these objects are present in the input image.
12. Additional Files Available
I can provide the following files if required:
-
Complete
full_spec.yaml -
labels.txt -
Training COCO annotation JSON
-
Validation COCO annotation JSON
-
Test COCO annotation JSON
-
model_epoch_063.pth -
Training logs
-
Evaluation logs
-
Inference logs
-
Original pretrained model inference results
-
Fine-tuned model inference results
-
Example images showing the difference between pretrained and fine-tuned model results
Summary
The main issue is:
The original pretrained TrafficCamNet Transformer Lite model detects cars correctly. After fine-tuning it on my custom 9-class dataset, the fine-tuned model does not detect the original car class or the newly trained classes, even though the model achieves mAP = 0.72 and mAP50 = 0.91 during validation.
I would like NVIDIA’s guidance on:
-
Why the original class is lost after fine-tuning.
-
Why the new classes are also not detected.
-
How pretrained weights and biases are handled when changing the number of classes.
-
What happens to the pretrained detection/classification head.
-
Whether my class mapping and
labels.txtare correct. -
Whether this could be catastrophic forgetting.
-
What the correct TAO fine-tuning procedure is for detecting all 9 classes.
-
What changes, if any, are required in the training, checkpoint, export, or inference configuration.