Deci-AI / super-gradients

Easily train or fine-tune SOTA computer vision models with one open source training library. The home of Yolo-NAS.
https://www.supergradients.com
Apache License 2.0
4.59k stars 509 forks source link

How to perform grid search for hyper parameter tunning? #1792

Closed isri-ram closed 9 months ago

isri-ram commented 9 months ago

💡 Your Question

I'm using VinBigdata Chest X-ray images for anomaly detection (object detection) with 14 classes. Train - 3515 images Valid - 879 images Total - 4394 images (P.S: The original dataset has 15k images. I did not use the remaining because it belongs to no findings class where there are no bboxes)

I trained the yolo_nas_m model with the below parameters i was able to get an mAP@0.5 score of 0.31 after training for 200 epochs.

I trained the YOLOv8 with default parameters for just 20 epochs the mAP@0.5 i got is 0.291.

train_data.dataset.transforms
train_params = {
    "silent_mode":True,
    "average_best_models":True,
    "warmup_mode": "LinearBatchLRWarmup",
    "warmup_initial_lr": 1e-5,
    "lr_warmup_steps":1000,
    "lr_warmup_epochs": 3,
    "initial_lr": 1e-3,
    "lr_mode": "CosineLRScheduler",
    "cosine_final_lr_ratio": 0.1,
    "optimizer": "AdamW",
    "optimizer_params": {"weight_decay": 0.00001},
    "zero_weight_decay_on_bias_and_bn": True,
    "batch_accumulate":1,
    "ema": True,
    "ema_params": {"decay": 0.997, "decay_type": "threshold"},
    "max_epochs": 500,
    "mixed_precision": True,
    "loss": PPYoloELoss(
        use_static_assigner=False,
        num_classes=len(dataset_params['classes'])
    ),
    "valid_metrics_list": [
        DetectionMetrics_050(
            score_thres=0.05,
            top_k_predictions=100,
            calc_best_score_thresholds= True,
            num_cls=len(dataset_params['classes']),
            normalize_targets=True,
            post_prediction_callback=PPYoloEPostPredictionCallback(
                score_threshold=0.05,
                nms_top_k=512,
                max_predictions=50,
                nms_threshold=0.7,
            )
        )
    ],
   "metric_to_watch": 'mAP@0.50',
    "greater_metric_to_watch_is_better": True
}

Is there anything wrong with my train parameters @BloodAxe ? Can i do Grid Search to get the best model parameters? if yes, then how?

Versions

No response

BloodAxe commented 9 months ago

Currently we don't provide end-to-end grid search feature. You should do it manually:

for lr in [1e-5, 1e-4, 1e-3]:
  train_params = {..., initial_lr=lr}
  trainer = Trainer(...)
  trainer.train(..., train_params=train_params)

Or via Hydra:

python train.py -m --config-name YOUR_RECIPE.YAML training_hyperparams.initial_lr=1e-3,1e-4,1e-5
BloodAxe commented 9 months ago

I trained the yolo_nas_m model with the below parameters i was able to get an mAP@0.5 score of 0.31 after training for 200 epochs. I trained the YOLOv8 with default parameters for just 20 epochs the mAP@0.5 i got is 0.291.

Have you used same LR in both cases? Could be an explanation.