### Install SuperGradients Source: https://github.com/deci-ai/super-gradients/blob/master/notebooks/how_to_run_model_predict.ipynb Installs the SuperGradients library. Use this command to set up the environment for the tutorial. ```python !pip install -qq super-gradients==3.7.1 ``` -------------------------------- ### Navigate to Training Example Directory Source: https://github.com/deci-ai/super-gradients/blob/master/documentation/source/qat_ptq_yolo_nas.md Change the working directory to the location of the training recipe example. ```bash cd /super_gradients/src/super_gradients/examples/train_from_recipe_example ``` -------------------------------- ### Install SuperGradients Source: https://github.com/deci-ai/super-gradients/blob/master/notebooks/what_are_recipes_and_how_to_use.ipynb Install the library using pip. ```bash !pip install -q super-gradients==3.7.1 ``` -------------------------------- ### Install SuperGradients Source: https://github.com/deci-ai/super-gradients/blob/master/src/super_gradients/examples/SG_Walkthrough.ipynb Install the library via pip. Use the commented-out command to install directly from the source repository. ```python # SuperGradients installation !pip install super-gradients gwpy &> /dev/null # To install from source instead of the last release, comment the command above and uncomment the following one. # !pip install git+https://github.com/Deci-AI/super_gradients.git ``` -------------------------------- ### Install SuperGradients Source: https://github.com/deci-ai/super-gradients/blob/master/src/super_gradients/examples/SG_quickstart_classification.ipynb Install the necessary library dependencies. ```bash ! pip install super_gradients gwpy &> /dev/null ``` -------------------------------- ### Install SuperGradients Source: https://github.com/deci-ai/super-gradients/blob/master/notebooks/transfer_learning_semantic_segmentation.ipynb Installs the SuperGradients library and its dependencies. Use this command to set up the environment for the tutorial. ```python ! pip install -qq super-gradients==3.7.1 ``` -------------------------------- ### Install SuperGradients and Dependencies Source: https://github.com/deci-ai/super-gradients/blob/master/notebooks/yolo_nas_custom_dataset_fine_tuning_with_qat.ipynb Install the required libraries for SuperGradients and dataset handling. ```bash !pip install -qq super-gradients==3.7.1 datasets[vision]~=2.1 pandas~=2.0 ``` -------------------------------- ### Navigate to QAT Example Directory Source: https://github.com/deci-ai/super-gradients/blob/master/documentation/source/qat_ptq_yolo_nas.md Change the current directory to the location of the `qat_from_recipe` example script. This is the first step before launching any QAT or PTQ related training. ```bash cd /super_gradients/src/super_gradients/examples/qat_from_recipe_example ``` -------------------------------- ### Main Recipe Configuration Example Source: https://github.com/deci-ai/super-gradients/blob/master/notebooks/what_are_recipes_and_how_to_use.ipynb An example of a main YAML recipe file aggregating various configuration components. ```yaml defaults: - training_hyperparams: coco2017_yolox_train_params - dataset_params: coco_detection_dataset_params - arch_params: yolox_s_arch_params - checkpoint_params: default_checkpoint_params train_dataloader: coco2017_train val_dataloader: coco2017_val model_checkpoints_location: local load_checkpoint: False training_hyperparams: initial_lr: 0.001 architecture: yolox_s multi_gpu: DDP num_gpus: 8 experiment_suffix: res${dataset_params.train_dataset_params.input_dim} experiment_name: ${architecture}_coco2017_${experiment_suffix} ``` -------------------------------- ### Install Super-Gradients and Deci Lab Client Source: https://github.com/deci-ai/super-gradients/blob/master/src/super_gradients/examples/SG_quickstart_model_upload_deci_lab.ipynb Install the necessary libraries for Super-Gradients and the Deci Lab client. This command suppresses output upon successful installation. ```bash ! pip install super_gradients deci-lab-client &> /dev/null ``` -------------------------------- ### Sample Log Output Source: https://github.com/deci-ai/super-gradients/blob/master/notebooks/DEKR_PoseEstimationFineTuning.ipynb Example of framework initialization logs, including warnings for missing optional dependencies. ```text [2023-12-19 09:59:11] INFO - crash_tips_setup.py - Crash tips is enabled. You can set your environment variable to CRASH_HANDLER=FALSE to disable it [2023-12-19 09:59:12] WARNING - __init__.py - Failed to import pytorch_quantization [2023-12-19 09:59:12] INFO - utils.py - NumExpr defaulting to 2 threads. [2023-12-19 09:59:22] WARNING - calibrator.py - Failed to import pytorch_quantization [2023-12-19 09:59:22] WARNING - export.py - Failed to import pytorch_quantization [2023-12-19 09:59:22] WARNING - selective_quantization_utils.py - Failed to import pytorch_quantization [2023-12-19 09:59:22] WARNING - env_sanity_check.py - Failed to verify installed packages: boto3 required but not found [2023-12-19 09:59:22] WARNING - env_sanity_check.py - Failed to verify installed packages: deprecated required but not found [2023-12-19 09:59:22] WARNING - env_sanity_check.py - Failed to verify installed packages: coverage required but not found [2023-12-19 09:59:22] WARNING - env_sanity_check.py - Failed to verify installed packages: sphinx-rtd-theme required but not found [2023-12-19 09:59:22] WARNING - env_sanity_check.py - Failed to verify installed packages: torchmetrics required but not found [2023-12-19 09:59:22] WARNING - env_sanity_check.py - Failed to verify installed packages: hydra-core required but not found [2023-12-19 09:59:22] WARNING - env_sanity_check.py - Failed to verify installed packages: omegaconf required but not found ``` -------------------------------- ### Learning Rate Warm-up Configuration Source: https://github.com/deci-ai/super-gradients/blob/master/notebooks/DEKR_PoseEstimationFineTuning.ipynb Set up learning rate warm-up parameters. This example shows how to configure linear epoch-step warm-up, though it's commented out for this specific example. ```yaml "warmup_mode": "linear_epoch_step", "warmup_initial_lr": 1e-3, "lr_warmup_epochs": 0, ``` -------------------------------- ### Installation Output Logs Source: https://github.com/deci-ai/super-gradients/blob/master/notebooks/detection_transfer_learning.ipynb Logs generated during the installation process. ```text /usr/local/lib/python3.10/dist-packages/ipykernel/ipkernel.py:283: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above. and should_run_async(code) ``` ```text Output: Num classes in the model: 2 Looking in indexes: https://pypi.org/simple, https://pypi.ngc.nvidia.com Collecting onnx_graphsurgeon==0.3.27 Downloading https://developer.download.nvidia.com/compute/redist/onnx-graphsurgeon/onnx_graphsurgeon-0.3.27-py2.py3-none-any.whl (42 kB)  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 42.1/42.1 kB 6.7 MB/s eta 0:00:00 [?25hRequirement already satisfied: numpy in /usr/local/lib/python3.10/dist-packages (from onnx_graphsurgeon==0.3.27) (1.23.0) Requirement already satisfied: onnx in /usr/local/lib/python3.10/dist-packages (from onnx_graphsurgeon==0.3.27) (1.13.0) Requirement already satisfied: protobuf<4,>=3.20.2 in /usr/local/lib/python3.10/dist-packages (from onnx->onnx_graphsurgeon==0.3.27) (3.20.3) Requirement already satisfied: typing-extensions>=3.6.2.1 in /usr/local/lib/python3.10/dist-packages (from onnx->onnx_graphsurgeon==0.3.27) (4.5.0) Installing collected packages: onnx_graphsurgeon Successfully installed onnx_graphsurgeon-0.3.27 ``` -------------------------------- ### Install Super Gradients Source: https://github.com/deci-ai/super-gradients/blob/master/README.md Commands to install the library from either the stable PyPi repository or directly from the GitHub source. ```bash pip install super-gradients ``` ```bash pip install git+https://github.com/Deci-AI/super-gradients.git@stable ``` -------------------------------- ### Install Super Gradients and dependencies Source: https://github.com/deci-ai/super-gradients/blob/master/notebooks/albumentations_tutorial.ipynb Use these commands to install the required versions of Super Gradients, Albumentations, and Datasets. ```bash ! pip install -qq super-gradients==3.7.1 ! pip install -qq albumentations == 1.3.1 ! pip install -qq datasets[vision]~=2.1 pandas~=2.0 ``` -------------------------------- ### Install SuperGradients and Dependencies Source: https://github.com/deci-ai/super-gradients/blob/master/notebooks/DEKR_PoseEstimationFineTuning.ipynb Install the required library version and dependencies for the pose estimation workflow. ```bash !pip install -q super_gradients==3.7.1 scikit-learn ``` -------------------------------- ### Initialize TensorBoard for Training Monitoring Source: https://github.com/deci-ai/super-gradients/blob/master/notebooks/how_to_use_knowledge_distillation_for_classification.ipynb Load the TensorBoard extension and start the server to monitor training progress from the specified log directory. ```python %load_ext tensorboard %tensorboard --logdir notebook_ckpts --bind_all ``` -------------------------------- ### Install PyTorch Quantization Source: https://github.com/deci-ai/super-gradients/blob/master/documentation/source/ptq_qat.md Install the required pytorch-quantization package from the NVIDIA NGC repository. ```shell pip install pytorch-quantization --extra-index-url https://pypi.ngc.nvidia.com ``` -------------------------------- ### QAT execution console output Source: https://github.com/deci-ai/super-gradients/blob/master/notebooks/yolo_nas_custom_dataset_fine_tuning_with_qat.ipynb Example console output showing parameter modifications and calibration progress. ```text W0315 10:22:31.036642 11412 pre_launch_callbacks.py:293] New number of epochs: 5 W0315 10:22:31.036642 11412 pre_launch_callbacks.py:300] New learning rate: 5e-06 W0315 10:22:31.036642 11412 pre_launch_callbacks.py:301] New weight decay: 1.0000000000000002e-06 W0315 10:22:31.036642 11412 pre_launch_callbacks.py:306] lr_mode will be set to cosine for QAT run instead of CosineLRScheduler with cosine_final_lr_ratio=0.01 W0315 10:22:31.036642 11412 pre_launch_callbacks.py:312] New lr_warmup_epochs: 1 Indexing dataset annotations: 100%|██████████| 1000/1000 [00:00<00:00, 7109.65it/s] Indexing dataset annotations: 100%|██████████| 29/29 [00:00 /dev/null pip install pytorch-quantization==2.1.2 --extra-index-url https://pypi.ngc.nvidia.com &> /dev/null ``` -------------------------------- ### Minimal Recipe Structure Example Source: https://github.com/deci-ai/super-gradients/blob/master/documentation/source/Recipes_Training.md A minimal example of a SuperGradients recipe YAML file, showcasing the 'defaults' key for including other configuration files and defining mandatory properties. ```yaml defaults: - training_hyperparams: cifar10_resnet_train_params - dataset_params: cifar10_dataset_params - arch_params: resnet18_cifar_arch_params - checkpoint_params: default_checkpoint_params - _self_ - variable_setup architecture: resnet18 train_dataloader: cifar10_train # Optional, see comments below val_dataloader: cifar10_val # Optional, see comments below multi_gpu: Off num_gpus: 1 experiment_suffix: "" experiment_name: cifar10_${architecture}${experiment_suffix} ``` -------------------------------- ### Install SuperGradients via PyPi Source: https://github.com/deci-ai/super-gradients/blob/master/documentation/source/installation.md Use this command to install the stable version of the library from the Python Package Index. ```bash pip install super-gradients ``` -------------------------------- ### Install and Configure Pre-Commit Hooks Source: https://github.com/deci-ai/super-gradients/blob/master/CONTRIBUTING.md Installs the pre-commit package and sets up Git hooks to automatically format code and run linter checks before each commit. Run these commands from the repository root. ```bash $ pip install pre-commit $ pre-commit install ``` -------------------------------- ### Initialize Cifar10 Dataset with Albumentations Source: https://github.com/deci-ai/super-gradients/blob/master/notebooks/albumentations_tutorial.ipynb Setup the Cifar10 dataset with specific Albumentations transforms and visualize the output. ```python from super_gradients.training.datasets import Cifar10 dataset = Cifar10( root="./data/cifar10", train=True, download=True, transforms={"Albumentations": {"Compose": {"transforms": [{"HorizontalFlip": {"p": 1.0}}, {"InvertImg": {"p": 1.0}}]}}}, ) plot_classification(dataset) ``` -------------------------------- ### Console Log Output Example Source: https://github.com/deci-ai/super-gradients/blob/master/notebooks/detection_how_to_connect_custom_dataset.ipynb This is an example of the console output during training, showing informational messages about the training process, dataset size, and run ID. It also indicates the directory where checkpoints are saved. ```text [2023-10-30 15:09:51] WARNING - sg_trainer.py - Train dataset size % batch_size != 0 and drop_last=False, this might result in smaller last batch. [2023-10-30 15:09:51] INFO - sg_trainer.py - Starting a new run with `run_id=RUN_20231030_150951_846432` [2023-10-30 15:09:51] INFO - sg_trainer.py - Checkpoints directory: /home/notebook_ckpts/transfer_learning_object_detection_yolox/RUN_20231030_150951_846432 ``` -------------------------------- ### Initialize Checkpoint Directory Source: https://github.com/deci-ai/super-gradients/blob/master/notebooks/DEKR_PoseEstimationFineTuning.ipynb Create a directory for saving checkpoints if it does not already exist. This is a common setup step for training. ```python from super_gradients.training import Trainer CHECKPOINT_DIR = 'checkpoints' os.makedirs(CHECKPOINT_DIR, exist_ok=True) ``` -------------------------------- ### Install Development Dependencies Source: https://github.com/deci-ai/super-gradients/blob/master/CONTRIBUTING.md Installs the necessary development dependencies, including Black, Flake8, and Git commit hooks. This command should be run from the project root. ```bash $ pip install -r requirements.dev.txt ``` -------------------------------- ### Display Dataloader Configuration Output Source: https://github.com/deci-ai/super-gradients/blob/master/documentation/source/Example_Classification.md Example output showing the structure of dataloader and dataset parameters. ```json Dataloader parameters: { "batch_size": 256, "drop_last": False, "num_workers": 2, "pin_memory": True, "shuffle": True } Dataset parameters: { "download": True, "root": "./data/cifar10", "target_transform": None, "train": True, "transforms": [ {"RandomCrop": {"size": 32, "padding": 4}}, "RandomHorizontalFlip", "ToTensor", {"Normalize": {"mean": [0.4914, 0.4822, 0.4465], "std": [0.2023, 0.1994, 0.201]}}, ] } ``` -------------------------------- ### Setup Advanced INT-8 Quantization Source: https://github.com/deci-ai/super-gradients/blob/master/src/super_gradients/examples/model_export/models_export.ipynb Import necessary modules for advanced INT-8 quantization using a calibration DataLoader. ```python import torch from torch.utils.data import DataLoader from super_gradients.conversion import ExportQuantizationMode ``` -------------------------------- ### Configure Environment and Install Dependencies Source: https://github.com/deci-ai/super-gradients/blob/master/notebooks/YoloNAS_Inference_using_TensorRT.ipynb Sets the preferred encoding to UTF-8 to avoid Colab-specific issues and installs the Super Gradients library along with required TensorRT and PyCUDA components. ```python # This hack is to prevent occasional issue in Colab https://github.com/googlecolab/colabtools/issues/3409 locale.getpreferredencoding = lambda *args: "UTF-8" ``` ```bash !pip install -qq super-gradients==3.7.1 !pip install -qq tensorrt~=8.6 pycuda pytorch-quantization==2.1.2 --extra-index-url https://pypi.ngc.nvidia.com ``` -------------------------------- ### Apply YOLO-NAS Model to FiftyOne Dataset Source: https://github.com/deci-ai/super-gradients/blob/master/README.md Apply a SuperGradients YOLO-NAS model to a FiftyOne dataset for object detection. This example shows how to load a dataset, get a pretrained model, and apply it, then launch a FiftyOne session. ```python import fiftyone as fo import fiftyone.zoo as foz from super_gradients.training import models dataset = foz.load_zoo_dataset("quickstart", max_samples=25) dataset.select_fields().keep_fields() model = models.get("yolo_nas_m", pretrained_weights="coco") dataset.apply_model(model, label_field="yolo_nas", confidence_thresh=0.7) session = fo.launch_app(dataset) ``` -------------------------------- ### Training and Testing Output Logs Source: https://github.com/deci-ai/super-gradients/blob/master/notebooks/yolo_nas_custom_dataset_fine_tuning_with_qat.ipynb Example console output showing checkpoint saving, training metrics, and testing progress. ```text [2024-03-15 10:21:55] INFO - base_sg_logger.py - Checkpoint saved in experiments\yolo_nas_s_cppe-5\RUN_20240315_101050_835636\ckpt_best.pth [2024-03-15 10:21:55] INFO - sg_trainer.py - Best checkpoint overriden: validation mAP@0.50: 0.8216230273246765 [2024-03-15 10:21:55] INFO - base_sg_logger.py - [CLEANUP] - Successfully stopped system monitoring process ``` ```text =========================================================== SUMMARY OF EPOCH 9 ├── Train │ ├── Ppyoloeloss/loss_cls = 0.8152 │ │ ├── Epoch N-1 = 0.8334 (\u001b[32m↘ -0.0183\u001b[0m) │ │ └── Best until now = 0.8334 (\u001b[32m↘ -0.0183\u001b[0m) │ ├── Ppyoloeloss/loss_iou = 0.4716 │ │ ├── Epoch N-1 = 0.4772 (\u001b[32m↘ -0.0056\u001b[0m) │ │ └── Best until now = 0.4772 (\u001b[32m↘ -0.0056\u001b[0m) │ ├── Ppyoloeloss/loss_dfl = 0.5164 │ │ ├── Epoch N-1 = 0.5244 (\u001b[32m↘ -0.0079\u001b[0m) │ │ └── Best until now = 0.5244 (\u001b[32m↘ -0.0079\u001b[0m) │ └── Ppyoloeloss/loss = 1.8032 │ ├── Epoch N-1 = 1.835 (\u001b[32m↘ -0.0318\u001b[0m) │ └── Best until now = 1.835 (\u001b[32m↘ -0.0318\u001b[0m) └── Validation ├── Ppyoloeloss/loss_cls = 0.8293 │ ├── Epoch N-1 = 0.8631 (\u001b[32m↘ -0.0338\u001b[0m) │ └── Best until now = 0.8443 (\u001b[32m↘ -0.015\u001b[0m) ├── Ppyoloeloss/loss_iou = 0.4506 │ ├── Epoch N-1 = 0.442 (\u001b[31m↗ 0.0086\u001b[0m) │ └── Best until now = 0.4397 (\u001b[31m↗ 0.0108\u001b[0m) ├── Ppyoloeloss/loss_dfl = 0.4698 │ ├── Epoch N-1 = 0.4672 (\u001b[31m↗ 0.0026\u001b[0m) │ └── Best until now = 0.4672 (\u001b[31m↗ 0.0026\u001b[0m) ├── Ppyoloeloss/loss = 1.7496 │ ├── Epoch N-1 = 1.7723 (\u001b[32m↘ -0.0227\u001b[0m) │ └── Best until now = 1.7704 (\u001b[32m↘ -0.0207\u001b[0m) ├── Precision@0.50 = 0.1557 │ ├── Epoch N-1 = 0.149 (\u001b[32m↗ 0.0067\u001b[0m) │ └── Best until now = 0.1773 (\u001b[31m↘ -0.0216\u001b[0m) ├── Recall@0.50 = 0.8957 │ ├── Epoch N-1 = 0.9081 (\u001b[31m↘ -0.0125\u001b[0m) │ └── Best until now = 0.9394 (\u001b[31m↘ -0.0437\u001b[0m) ├── Map@0.50 = 0.8216 │ ├── Epoch N-1 = 0.779 (\u001b[32m↗ 0.0426\u001b[0m) │ └── Best until now = 0.779 (\u001b[32m↗ 0.0426\u001b[0m) ├── F1@0.50 = 0.262 │ ├── Epoch N-1 = 0.2504 (\u001b[32m↗ 0.0117\u001b[0m) │ └── Best until now = 0.2528 (\u001b[32m↗ 0.0092\u001b[0m) ├── Ap@0.50_coverall = 0.83 │ ├── Epoch N-1 = 0.8648 (\u001b[31m↘ -0.0349\u001b[0m) │ └── Best until now = 0.8648 (\u001b[31m↘ -0.0349\u001b[0m) ├── Ap@0.50_face_shield = 0.9545 │ ├── Epoch N-1 = 0.8264 (\u001b[32m↗ 0.1281\u001b[0m) │ └── Best until now = 0.8936 (\u001b[32m↗ 0.0609\u001b[0m) ├── Ap@0.50_gloves = 0.7184 │ ├── Epoch N-1 = 0.6491 (\u001b[32m↗ 0.0694\u001b[0m) │ └── Best until now = 0.6699 (\u001b[32m↗ 0.0485\u001b[0m) ├── Ap@0.50_goggles = 0.7598 │ ├── Epoch N-1 = 0.734 (\u001b[32m↗ 0.0258\u001b[0m) │ └── Best until now = 0.7511 (\u001b[32m↗ 0.0087\u001b[0m) ├── Ap@0.50_mask = 0.8455 │ ├── Epoch N-1 = 0.8209 (\u001b[32m↗ 0.0245\u001b[0m) │ └── Best until now = 0.8746 (\u001b[31m↘ -0.0291\u001b[0m) ├── Best_score_threshold = 0.4 │ ├── Epoch N-1 = 0.35 (↗ 0.05\u001b[0m) │ └── Best until now = 0.27 (↗ 0.13\u001b[0m) ├── Best_score_threshold_coverall = 0.42 │ ├── Epoch N-1 = 0.34 (↗ 0.08\u001b[0m) │ └── Best until now = 0.16 (↗ 0.26\u001b[0m) ├── Best_score_threshold_face_shield = 0.44 │ ├── Epoch N-1 = 0.45 (↘ -0.01\u001b[0m) │ └── Best until now = 0.09 (↗ 0.35\u001b[0m) ├── Best_score_threshold_gloves = 0.24 │ ├── Epoch N-1 = 0.37 (↘ -0.13\u001b[0m) │ └── Best until now = 0.09 (↗ 0.15\u001b[0m) ├── Best_score_threshold_goggles = 0.29 │ ├── Epoch N-1 = 0.35 (↘ -0.06\u001b[0m) │ └── Best until now = 0.0 (↗ 0.29\u001b[0m) └── Best_score_threshold_mask = 0.45 ├── Epoch N-1 = 0.32 (↗ 0.13\u001b[0m) └── Best until now = 0.32 (↗ 0.13\u001b[0m) =========================================================== ``` ```text [2024-03-15 10:21:56] INFO - checkpoint_utils.py - Successfully loaded model weights from experiments\yolo_nas_s_cppe-5\RUN_20240315_101050_835636\ckpt_best.pth checkpoint. Testing: 50%|█████ | 1/2 [00:00<00:00, 1.48it/s] ``` -------------------------------- ### Install environment dependencies Source: https://github.com/deci-ai/super-gradients/blob/master/notebooks/YoloNAS_Inference_using_TensorRT.ipynb Initializes the environment by importing the locale module, which is a prerequisite for subsequent library configurations. ```python import locale ``` -------------------------------- ### Load YOLO-NAS Model from FiftyOne Zoo Source: https://github.com/deci-ai/super-gradients/blob/master/README.md Load a YOLO-NAS model directly from the FiftyOne Model Zoo and apply it to a dataset. This example demonstrates loading the model and then applying it to a quickstart dataset before launching the FiftyOne app. ```python import fiftyone as fo import fiftyone.zoo as foz model = foz.load_zoo_model("yolo-nas-torch") dataset = foz.load_zoo_dataset("quickstart") dataset.apply_model(model, label_field="yolo_nas") session = fo.launch_app(dataset) ``` -------------------------------- ### Run QAT from Recipe Source: https://context7.com/deci-ai/super-gradients/llms.txt Initiate Quantization-Aware Training using a configuration recipe via the command line. This allows for easy setup and execution of QAT experiments. ```bash python -m super_gradients.train_from_recipe \ --config-name=coco2017_yolo_nas_s_qat \ dataset_params.data_dir=/path/to/coco ``` -------------------------------- ### Pip Installation Result Source: https://github.com/deci-ai/super-gradients/blob/master/notebooks/YoloNAS_Inference_using_TensorRT.ipynb Shows the result of a pip installation command, indicating that the specified package is already installed and satisfied. ```text Requirement already satisfied: numpy in /usr/local/lib/python3.10/dist-packages (1.23.0) ``` ```text Requirement already satisfied: onnx in /usr/local/lib/python3.10/dist-packages (1.13.0) ``` ```text Requirement already satisfied: protobuf<4,>=3.20.2 in /usr/local/lib/python3.10/dist-packages (3.20.3) ``` ```text Requirement already satisfied: typing-extensions>=3.6.2.1 in /usr/local/lib/python3.10/dist-packages (4.9.0) ``` -------------------------------- ### Configure and Start Training Source: https://github.com/deci-ai/super-gradients/blob/master/src/super_gradients/examples/SG_quickstart_model_upload_deci_lab.ipynb Set up training parameters such as epochs, learning rate schedule, loss function, metrics, and callbacks. Then, initiate the training process using the trainer.train() method. ```python training_params={ "max_epochs": 2, "lr_updates": [1], "lr_decay_factor": 0.1, "lr_mode": "step", "lr_warmup_epochs": 0, "initial_lr": 0.1, "loss": "cross_entropy", "optimizer": optimizer, "criterion_params": {}, "train_metrics_list": [Accuracy(), Top5()], "valid_metrics_list": [Accuracy(), Top5()], "loss_logging_items_names": ["Loss"], "metric_to_watch": "Accuracy", "greater_metric_to_watch_is_better": True, "phase_callbacks": phase_callbacks } trainer.train(training_params=training_params) ``` -------------------------------- ### Install Super-Gradients Source: https://github.com/deci-ai/super-gradients/blob/master/documentation/source/models_export_pose.md Install the Super-Gradients library to use its pose estimation model export functionalities. This command installs version 3.4.0. ```python !pip install -qq super-gradients==3.4.0 ``` -------------------------------- ### Install SuperGradients Source: https://github.com/deci-ai/super-gradients/blob/master/notebooks/detection_how_to_connect_custom_dataset.ipynb Installs the super_gradients library and its dependencies. ```python ! pip install -q super_gradients==3.7.1 ``` -------------------------------- ### Launch Training from Recipe Source: https://github.com/deci-ai/super-gradients/blob/master/documentation/source/Data.md Import the registered dataset class to trigger registration, then use Trainer.train_from_config. ```python from omegaconf import DictConfig import hydra import pkg_resources from my_dataset import MyCustomDataset from super_gradients import Trainer, init_trainer @hydra.main(config_path=pkg_resources.resource_filename("super_gradients.recipes", ""), version_base="1.2") def main(cfg: DictConfig) -> None: Trainer.train_from_config(cfg) def run(): init_trainer() main() if __name__ == "__main__": run() ``` -------------------------------- ### Launch Training with Recipe Source: https://github.com/deci-ai/super-gradients/blob/master/documentation/source/qat_ptq_yolo_nas.md Execute the training process using the specified configuration file and dataset parameters. ```bash python -m train_from_recipe --config-name=roboflow_yolo_nas_s dataset_name=soccer-players-5fuqs dataset_params.data_dir= ckpt_root_dir= experiment_name=yolo_nas_s_soccer_players ``` -------------------------------- ### Test Pretrained BEiT Model on CIFAR10 Source: https://github.com/deci-ai/super-gradients/blob/master/notebooks/how_to_use_knowledge_distillation_for_classification.ipynb Initialize a Trainer, get CIFAR10 test dataloader with resized images, load a pretrained BEiT model, and evaluate it using Accuracy and Top5 metrics. Ensure the dataset transforms are set to resize images to 224x224. ```python import os from super_gradients.training import Trainer, models, dataloaders from super_gradients.training.metrics import Accuracy, Top5 from torchvision import transforms checkpoint_dir = os.path.abspath("notebook_ckpts") trainer = Trainer(experiment_name="beit_base_patch16_224_test", ckpt_root_dir=checkpoint_dir) test_dataloader = dataloaders.get("cifar10_val", dataloader_params={"batch_size": 64, "num_workers": 2}, dataset_params={"transforms": [transforms.ToTensor(), transforms.Resize(224)]}) pretrained_beit = models.get('beit_base_patch16_224', arch_params={'num_classes': 10, "image_size": [224, 224], "patch_size": [16, 16]}, pretrained_weights="cifar10") metrics = trainer.test(model=pretrained_beit, test_loader=test_dataloader, test_metrics_list=[Accuracy(), Top5()]) print() print(f"Accuracy: {metrics['Accuracy']:.3f}") print(f"Top 5: {metrics['Top5']:.3f}") ``` -------------------------------- ### Instantiate and train YoloNAS model Source: https://github.com/deci-ai/super-gradients/blob/master/notebooks/yolo_nas_custom_dataset_fine_tuning_with_qat.ipynb Initializes a YoloNAS_S model with pre-trained COCO weights and starts the training loop. Ensure NUM_CLASSES, train_params, train_loader, and valid_loader are defined before execution. ```python from super_gradients.training import Trainer from super_gradients.common.object_names import Models from super_gradients.training import models trainer = Trainer(experiment_name="yolo_nas_s_cppe-5", ckpt_root_dir="experiments") model = models.get(Models.YOLO_NAS_S, num_classes=NUM_CLASSES, pretrained_weights="coco") trainer.train(model=model, training_params=train_params, train_loader=train_loader, valid_loader=valid_loader) ``` -------------------------------- ### Set Up Training Device Source: https://github.com/deci-ai/super-gradients/blob/master/documentation/source/QuickstartBasicToolkit.md Configure the device for training. Use 'cpu' for CPU-only training, specify a number of GPUs for multi-GPU DDP training, or use -1 to utilize all available GPUs. ```python setup_device("cpu") ``` ```python setup_device(num_gpus=4) ``` ```python setup_device(num_gpus=-1) ``` -------------------------------- ### Load DataLoaders and Student Model Source: https://github.com/deci-ai/super-gradients/blob/master/notebooks/how_to_use_knowledge_distillation_for_classification.ipynb Get training and validation data loaders for CIFAR10, and instantiate a ResNet18 model as the student network. ```python from super_gradients.training import dataloaders, models train_dataloader = dataloaders.get("cifar10_train", dataloader_params={"batch_size": 128, "num_workers": 2}) val_dataloader = dataloaders.get("cifar10_val", dataloader_params={"batch_size": 512, "num_workers": 2}) student_resnet18 = models.get('resnet18_cifar', num_classes=10) ``` -------------------------------- ### Install onnx_graphsurgeon Source: https://github.com/deci-ai/super-gradients/blob/master/notebooks/detection_transfer_learning.ipynb Install the required onnx_graphsurgeon package from the NVIDIA NGC index. ```bash !pip install onnx_graphsurgeon==0.3.27 --extra-index-url https://pypi.ngc.nvidia.com ``` -------------------------------- ### ONNX Runtime Inference Example Source: https://github.com/deci-ai/super-gradients/blob/master/documentation/source/models_export_pose.md Example code to set up ONNX Runtime session and run inference. It retrieves input and output names and processes a zero-filled numpy array as an example input. ```python import onnxruntime import numpy as np session = onnxruntime.InferenceSession("yolo_nas_pose_s.onnx", providers=["CUDAExecutionProvider", "CPUExecutionProvider"]) inputs = [o.name for o in session.get_inputs()] outputs = [o.name for o in session.get_outputs()] example_input_image = np.zeros((1, 3, 640, 640)).astype(np.uint8) predictions = session.run(outputs, {inputs[0]: example_input_image}) ``` -------------------------------- ### Pip Installation Success Source: https://github.com/deci-ai/super-gradients/blob/master/notebooks/YoloNAS_Inference_using_TensorRT.ipynb Confirms the successful installation of collected packages via pip. ```text Installing collected packages: onnx_graphsurgeon Successfully installed onnx_graphsurgeon-0.3.27 ``` -------------------------------- ### Initialize Quantization-Aware Training (QAT) Source: https://context7.com/deci-ai/super-gradients/llms.txt Set up a QATTrainer for training models with quantization awareness. This involves loading a pre-trained model, preparing calibration data, and defining QAT-specific training parameters. ```python from super_gradients.training import QATTrainer, models from super_gradients.training.dataloaders import dataloaders qat_trainer = QATTrainer( experiment_name="yolo_nas_qat", ckpt_root_dir="/path/to/checkpoints" ) model = models.get(Models.YOLO_NAS_S, pretrained_weights="coco") train_loader = dataloaders.get( name="coco2017_train_yolo_nas", dataset_params={"data_dir": "/path/to/coco"}, dataloader_params={"batch_size": 16} ) val_loader = dataloaders.get( name="coco2017_val_yolo_nas", dataset_params={"data_dir": "/path/to/coco"}, dataloader_params={"batch_size": 16} ) qat_params = { "max_epochs": 10, "initial_lr": 1e-5, "optimizer": "Adam", "loss": "PPYoloELoss", "mixed_precision": False, # QAT doesn't support mixed precision } qat_trainer.train( model=model, training_params=qat_params, train_loader=train_loader, valid_loader=val_loader ) ``` -------------------------------- ### Train KD from Recipe Source: https://context7.com/deci-ai/super-gradients/llms.txt Initiate knowledge distillation training using a configuration recipe via the command line. This method simplifies setup by referencing predefined configurations. ```bash python -m super_gradients.train_from_kd_recipe \ --config-name=cifar10_resnet_kd \ student_architecture=resnet18 \ teacher_architecture=beit_base_patch16_224 ``` -------------------------------- ### Launch TensorBoard Source: https://github.com/deci-ai/super-gradients/blob/master/notebooks/PTQ_and_QAT_for_classification.ipynb Enable TensorBoard integration to visualize training progress live. Ensure the log directory is correctly specified. ```python %load_ext tensorboard %tensorboard --logdir checkpoints ``` -------------------------------- ### Install Dependencies Source: https://github.com/deci-ai/super-gradients/blob/master/tutorials/DagsHub_X_SuperGradients.ipynb Install the required libraries for SuperGradients, DagsHub, and compatible versions of Matplotlib and Pillow. ```python !pip install super_gradients !pip install dagshub mlflow --quiet !pip install matplotlib==3.1.3 --quiet !python -m pip install --upgrade pillow==9.2.0 --quiet !pip install --upgrade Pillow --quiet ``` -------------------------------- ### Standard Imports and Setup Source: https://github.com/deci-ai/super-gradients/blob/master/notebooks/YoloNAS_Pose_Fine_Tuning_Animals_Pose_Dataset.ipynb Imports necessary libraries for data manipulation, model training, and visualization. Sets the device to CUDA if available, otherwise CPU. ```python # @title Some standard imports # Standard library imports import json import os import random from typing import List, Tuple, Union # Third-party imports import gdown import cv2 import matplotlib.image as mpimg import matplotlib.pyplot as plt import numpy as np import torch import yaml from sklearn.model_selection import train_test_split # Colab specific imports # Constants device = "cuda" if torch.cuda.is_available() else "cpu" ``` -------------------------------- ### Install SuperGradients Source: https://github.com/deci-ai/super-gradients/blob/master/documentation/source/models_export.md Install the required version of the SuperGradients library to enable model export functionality. ```python !pip install -qq super_gradients==3.4.0 ``` -------------------------------- ### Initialize Distributed Training Environment Source: https://context7.com/deci-ai/super-gradients/llms.txt Set up the environment for distributed training using DDP. This involves initializing the trainer and configuring the device for multi-GPU or multi-node training. ```python from super_gradients import init_trainer, Trainer from super_gradients.training.utils.distributed_training_utils import setup_device from super_gradients.common import MultiGPUMode init_trainer() setup_device( device="cuda", multi_gpu=MultiGPUMode.DISTRIBUTED_DATA_PARALLEL, num_gpus=4 ) trainer = Trainer(experiment_name="ddp_training") trainer.train(model=model, training_params=params, train_loader=train_loader, valid_loader=val_loader) ``` -------------------------------- ### Launch Training with Trainer Source: https://github.com/deci-ai/super-gradients/blob/master/documentation/source/Segmentation.md Initialize the Trainer and execute the training process. Requires valid model, training parameters, and data loaders. ```python from super_gradients import Trainer trainer = Trainer( experiment_name="segmentation_example", # Your experiment checkpoints and logs will be saved in a folder names after the experiment_name. ckpt_root_dir='/path/to/experiment/folder' # Path to the folder where you want to save all of your experiments. ) trainer.train(model=model, training_params=training_params, train_loader=train_dataloader, valid_loader=valid_dataloader) ``` -------------------------------- ### Install SuperGradients Source: https://github.com/deci-ai/super-gradients/blob/master/notebooks/detection_transfer_learning.ipynb Installs the super_gradients library and its dependencies. It's recommended to use a specific version for consistency. ```bash ! pip install -qq super_gradients==3.7.1 ``` -------------------------------- ### Install onnx_graphsurgeon Source: https://github.com/deci-ai/super-gradients/blob/master/notebooks/YoloNAS_Inference_using_TensorRT.ipynb Installs the onnx_graphsurgeon package version 0.3.27. This is often a dependency for ONNX model manipulation. ```bash pip install onnx_graphsurgeon==0.3.27 ``` -------------------------------- ### Setup TensorBoard Logging Source: https://github.com/deci-ai/super-gradients/blob/master/src/super_gradients/examples/SG_quickstart_tensorboard_logger.ipynb This snippet loads the TensorBoard extension and configures it to log from the specified checkpoint directory. This is useful for visualizing training progress. ```python %load_ext tensorboard %tensorboard --logdir {CHECKPOINT_DIR}/ ``` -------------------------------- ### Launch PTQ and QAT Training Source: https://github.com/deci-ai/super-gradients/blob/master/documentation/source/qat_ptq_yolo_nas.md Execute the QAT training script with specified configuration and experiment parameters. This command launches both Post-Training Quantization (PTQ) and Quantization-Aware Training (QAT). Ensure to replace placeholders with your actual paths. ```bash python -m qat_from_recipe --config-name=roboflow_yolo_nas_s_qat experiment_name=soccer_players_qat_yolo_nas_s dataset_name=soccer-players-5fuqs dataset_params.data_dir= checkpoint_params.checkpoint_path=/yolo_nas_s_soccer_players/ckpt_best.pth ckpt_ckpt_root_dir= ``` -------------------------------- ### Install Super Gradients Source: https://github.com/deci-ai/super-gradients/blob/master/notebooks/Segmentation_Model_Export.ipynb Install the required version of the Super Gradients library to access the export API. ```python !pip install -qq super_gradients==3.7.1 ``` -------------------------------- ### Launch Tensorboard Source: https://github.com/deci-ai/super-gradients/blob/master/documentation/source/logs.md Command to visualize training metrics using the generated Tensorboard event files. ```bash tensorboard --logdir // ``` -------------------------------- ### Install SuperGradients via GitHub Source: https://github.com/deci-ai/super-gradients/blob/master/documentation/source/installation.md Use this command to install the stable version of the library directly from the GitHub repository. ```bash pip install git+https://github.com/Deci-AI/super-gradients.git@stable ``` -------------------------------- ### Launch Model Training Source: https://github.com/deci-ai/super-gradients/blob/master/documentation/source/QuickstartBasicToolkit.md Start the model training process using the configured model, training parameters, and data loaders. ```python trainer.train(model=model, training_params=training_params, train_loader=train_loader, valid_loader=valid_loader) ``` -------------------------------- ### Launch Training via CLI Source: https://github.com/deci-ai/super-gradients/blob/master/notebooks/what_are_recipes_and_how_to_use.ipynb Executes a training recipe using the command line interface with configuration overrides. ```bash !python -m super_gradients.train_from_recipe --config-name=cifar10_resnet num_workers=0 epochs=20 ``` -------------------------------- ### Install SuperGradients and Dependencies Source: https://github.com/deci-ai/super-gradients/blob/master/notebooks/PTQ_and_QAT_for_classification.ipynb Installs the super-gradients library and pytorch-quantization. Ensure you are in a GPU and TensorRT environment as quantization is exclusively supported there. ```python !pip -qq install super-gradients==3.7.1 pytorch-quantization==2.1.2 --extra-index-url https://pypi.ngc.nvidia.com ``` -------------------------------- ### QAT Configuration Example Source: https://github.com/deci-ai/super-gradients/blob/master/documentation/source/qat_ptq_yolo_nas.md This YAML configuration inherits from a base recipe and modifies parameters for Quantization-Aware Training (QAT). It specifies checkpoint paths, experiment names, and callback modifications for QAT. ```yaml defaults: - roboflow_yolo_nas_s - quantization_params: default_quantization_params - _self_ checkpoint_params: checkpoint_path: ??? strict_load: no_key_matching experiment_name: soccer_players_qat_yolo_nas_s pre_launch_callbacks_list: - QATRecipeModificationCallback: batch_size_divisor: 2 max_epochs_divisor: 10 lr_decay_factor: 0.01 warmup_epochs_divisor: 10 cosine_final_lr_ratio: 0.01 disable_phase_callbacks: True disable_augmentations: False ``` -------------------------------- ### Install SuperGradients and gdown Source: https://github.com/deci-ai/super-gradients/blob/master/notebooks/YoloNAS_Pose_Fine_Tuning_Animals_Pose_Dataset.ipynb Installs the super-gradients library version 3.7.1 and the gdown package, which is used for downloading files from Google Drive. ```bash !pip install -qq super-gradients==3.7.1 gdown ``` -------------------------------- ### Training Log Output Example Source: https://github.com/deci-ai/super-gradients/blob/master/tutorials/DagsHub_X_SuperGradients.ipynb Example log output showing the initialization of EMA (Exponential Moving Average) with specified parameters. ```text Output: [2023-05-07 17:36:51] INFO - sg_trainer.py - Using EMA with params {'decay': 0.9, 'decay_type': 'threshold'} ```