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 510 forks source link

AttributeError: 'Trainer' object has no attribute 'train_loader' #1284

Closed kumarsyamala closed 1 year ago

kumarsyamala commented 1 year ago

🐛 Describe the bug

I am trying to run the yolo-nas model in google-collab and getting this error


  MODEL_ARCH = 'yolo_nas_l'
  BATCH_SIZE = 8
  MAX_EPOCHS = 25
  CHECKPOINT_DIR = 'new-checkpoints'
  EXPERIMENT_NAME = "faucet_poc"
  LOCATION = "/content/"
  CLASSES = ["faucet","sink","toilet"]

  dataset_params = {
      'data_dir': LOCATION,
      'train_images_dir':'train',
      'train_labels_dir':'108/train',
      'val_images_dir':'valid',
      'val_labels_dir':'108/valid',
      'test_images_dir':'test',
      'test_labels_dir':'108/test',
      'classes': CLASSES
  }
  from super_gradients.training.dataloaders.dataloaders import (
    coco_detection_yolo_format_train, coco_detection_yolo_format_val)

  train_data = coco_detection_yolo_format_train(
      dataset_params={
          'data_dir': dataset_params['data_dir'],
          'images_dir': dataset_params['train_images_dir'],
          'labels_dir': dataset_params['train_labels_dir'],
          'classes': dataset_params['classes']
      },
      dataloader_params={
          'batch_size': BATCH_SIZE,
          'num_workers': 2
      }
  )

  val_data = coco_detection_yolo_format_val(
      dataset_params={
          'data_dir': dataset_params['data_dir'],
          'images_dir': dataset_params['val_images_dir'],
          'labels_dir': dataset_params['val_labels_dir'],
          'classes': dataset_params['classes']
      },
      dataloader_params={
          'batch_size': BATCH_SIZE,
          'num_workers': 2
      }
  )

  from super_gradients.training.losses import PPYoloELoss
  from super_gradients.training.metrics import DetectionMetrics_050
  from super_gradients.training.models.detection_models.pp_yolo_e import PPYoloEPostPredictionCallback

  train_params = {
      # ENABLING SILENT MODE
      'silent_mode': True,
      "average_best_models":True,
      "warmup_mode": "linear_epoch_step",
      "warmup_initial_lr": 1e-6,
      "lr_warmup_epochs": 3,
      "initial_lr": 5e-4,
      "lr_mode": "cosine",
      "cosine_final_lr_ratio": 0.1,
      "optimizer": "Adam",
      "optimizer_params": {"weight_decay": 0.0001},
      "zero_weight_decay_on_bias_and_bn": True,
      "ema": True,
      "ema_params": {"decay": 0.9, "decay_type": "threshold"},
      # ONLY TRAINING FOR 10 EPOCHS FOR THIS EXAMPLE NOTEBOOK
      "max_epochs": 10,
      "mixed_precision": False,
      "loss": PPYoloELoss(
          use_static_assigner=False,
          # NOTE: num_classes needs to be defined here
          num_classes=len(dataset_params['classes']),
          reg_max=16
      ),
      "valid_metrics_list": [
          DetectionMetrics_050(
              score_thres=0.1,
              top_k_predictions=300,
              # NOTE: num_classes needs to be defined here
              num_cls=len(dataset_params['classes']),
              normalize_targets=True,
              post_prediction_callback=PPYoloEPostPredictionCallback(
                  score_threshold=0.01,
                  nms_top_k=1000,
                  max_predictions=300,
                  nms_threshold=0.7
              )
          )
      ],
      "metric_to_watch": 'mAP@0.50'
  }

  from super_gradients.training import Trainer

  CHECKPOINT_DIR = CHECKPOINT_DIR
  trainer = Trainer(experiment_name=EXPERIMENT_NAME, ckpt_root_dir=CHECKPOINT_DIR)

  trainer.train(model=model,
                training_params=train_params,
                train_loader=train_data,
                valid_loader=val_data)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
[<ipython-input-26-f1f176c64ec1>](https://localhost:8080/#) in <cell line: 1>()
----> 1 trainer.train(model=model,
      2               training_params=train_params,
      3               train_loader=train_data,
      4               valid_loader=val_data)

[/usr/local/lib/python3.10/dist-packages/super_gradients/training/sg_trainer/sg_trainer.py](https://localhost:8080/#) in train(self, model, training_params, train_loader, valid_loader, additional_configs_to_log)
    998         if training_params is None:
    999             training_params = dict()
-> 1000         self.train_loader = train_loader or self.train_loader
   1001         self.valid_loader = valid_loader or self.valid_loader
   1002 

AttributeError: 'Trainer' object has no attribute 'train_loader'

Versions

google collab. python 3.10 and 3.8

Louis-Dupont commented 1 year ago

Hi @kumarsyamala which version of super-gradients are you using ? It looks to me like you are using super-gradients=<3.1.1 and if it's the case I invite you to try with 3.1.2 or 3.1.3 and let me know if it fixes it.