1.1.0

roboflow/rf-detr1.1.0Apr 3, 2025by SkalskiP

AI Summary

Focused on training utilities including early stopping, gradient checkpointing, and experiment logging integrations.

Key Highlights

  • Implemented Early stopping to halt training when improvements are minimal.
  • Added Gradient checkpointing to reduce peak memory usage.
  • Integrated TensorBoard for real-time training visualization.
  • Integrated Weights and Biases (W&B) for collaborative experiment tracking.
  • Implemented automated GitHub Actions workflow for PyPI publishing.

New Features

  • Early stopping with configurable parameters.
  • Gradient checkpointing to enable larger batch sizes.
  • Automatic saving of training metrics.
  • TensorBoard logging support.
  • Weights and Biases (W&B) logging support.
  • Automated PyPI publishing.
  • Resume training functionality from checkpoints.

Full Release Notes

# Changelog

https://github.com/user-attachments/assets/87a3cefe-f3d1-42df-a799-f1d45dddf75e

## 🚀 Added

- Early stopping - Early stopping monitors validation mAP and halts training if improvements remain below a threshold for a set number of epochs. This can reduce wasted computation once the model converges. Additional parameters—such as `early_stopping_patience`, `early_stopping_min_delta`, and `early_stopping_use_ema`—let you fine-tune the stopping behavior. (https://github.com/roboflow/rf-detr/pull/87)

```python
from rfdetr import RFDETRBase

model = RFDETRBase()

model.train(dataset_dir=<DATASET_PATH>, epochs=12, batch_size=4, grad_accum_steps=4, early_stopping=True)
```

- Gradient checkpointing - Gradient checkpointing - Gradient checkpointing re-computes certain parts of the forward pass during backpropagation to reduce peak memory usage. This allows training larger models or higher batch sizes on limited GPU memory at the cost of slightly longer training time. Enable it by setting `gradient_checkpointing=True`. (https://github.com/roboflow/rf-detr/pull/91)

```python
from rfdetr import RFDETRBase

model = RFDETRBase()

model.train(dataset_dir=<DATASET_PATH>, epochs=12, batch_size=8, grad_accum_steps=2, gradient_checkpointing=True)
```

- Saving metrics - Training and validation metrics (e.g., losses, mAP) are now automatically saved to your output directory after training. (https://github.com/roboflow/rf-detr/pull/58)

![427308662-9088a1c0-fc20-495d-8237-a65d3881fbd5](https://github.com/user-attachments/assets/faa37772-8a7f-4c52-8989-bfd20e763f68)

- Logging with TensorBoard - Added support for logging training progress and metrics to TensorBoard, providing live visualizations of your model’s performance. Simply pass `tensorboard=True` to `.train()`, then run `tensorboard --logdir <OUTPUT_DIR>` to monitor. (https://github.com/roboflow/rf-detr/pull/62)

    <details>
    <summary>Using TensorBoard with RF-DETR</summary>
    
    <br>
    
    - TensorBoard logging requires additional packages. Install them with:
    
        ```bash
        pip install "rfdetr[metrics]"
        ```
      
    - To activate logging, pass the extra parameter `tensorboard=True` to `.train()`:
    
        ```python
        from rfdetr import RFDETRBase
        
        model = RFDETRBase()
        
        model.train(dataset_dir=<DATASET_PATH>, epochs=12, batch_size=4, grad_accum_steps=4, tensorboard=True, output_dir=<OUTPUT_PATH>)
        ```
    
    - To use TensorBoard locally, navigate to your project directory and run:
    
        ```bash
        tensorboard --logdir <OUTPUT_DIR>
        ```
    
        Then open `http://localhost:6006/` in your browser to view your logs.
    
    - To use TensorBoard in Google Colab run:
    
        ```bash
        %load_ext tensorboard
        %tensorboard --logdir <OUTPUT_DIR>
        ```
          
    </details>

- Logging with Weights and Biases - Integrated Weights and Biases (W&B) for collaborative, cloud-based experiment tracking. Passing wandb=True to .train() will automatically log metrics, hyperparameters, and system stats to your W&B project. (https://github.com/roboflow/rf-detr/pull/70)

    <details>
    <summary>Using Weights and Biases with RF-DETR</summary>
    
    <br>
    
    - Weights and Biases logging requires additional packages. Install them with:
    
        ```bash
        pip install "rfdetr[metrics]"
        ```
    
    - Before using W&B, make sure you are logged in:
    
        ```bash
        wandb login
        ```
    
        You can retrieve your API key at wandb.ai/authorize.
    
    - To activate logging, pass the extra parameter `wandb=True` to `.train()`:
    
        ```python
        from rfdetr import RFDETRBase
        
        model = RFDETRBase()
        
        model.train(dataset_dir=<DATASET_PATH>, epochs=12, batch_size=4, grad_accum_steps=4, wandb=True, project=<PROJECT_NAME>, run=<RUN_NAME>)
        ```
    
        In W&B, projects are collections of related machine learning experiments, and runs are individual sessions where training or evaluation happens. If you don't specify a name for a run, W&B will assign a random one automatically.
      
    </details>

- Automated Python package publish - Implemented a GitHub Actions workflow to build and publish the `rfdetr` package to PyPI on each new release, ensuring the latest version is immediately available. (https://github.com/roboflow/rf-detr/pull/71) 

## đź”§ Fixed

- Resume training - You can resume training from a previously saved checkpoint by passing the path to the `checkpoint.pth` file using the `resume` argument. This is useful when training is interrupted or you want to continue fine-tuning an already partially trained model. The training loop will automatically load the weights and optimizer state from the provided checkpoint file. (https://github.com/roboflow/rf-detr/pull/88)

```python
from rfdetr import RFDETRBase

model = RFDETRBase()

model.train(dataset_dir=<DATASET_PATH>, epochs=12, batch_size=4, grad_accum_steps=4, resume=<CHECKPOINT_PATH>)
```

# 🏆 Contributors

@mario-dg ([Mario da Graca](https://www.linkedin.com/in/mario-da-graca-1796b8273/overlay/about-this-profile/)), @onuralpszr ([Onuralp SEZER](https://www.linkedin.com/in/osezer/)), @farukalamai ([Md Faruk Alam](https://www.linkedin.com/in/farukalamai/overlay/about-this-profile/)), @probicheaux ([Peter Robicheaux](https://www.linkedin.com/in/peter-robicheaux-01958813b/overlay/about-this-profile/)), @isaacrob-roboflow ([Isaac Robinson](https://www.linkedin.com/in/robinsonish/overlay/about-this-profile/)), @Matvezy ([Matvei Popov](https://www.linkedin.com/in/matvezy/overlay/about-this-profile/)), @SkalskiP ([Piotr Skalski](https://www.linkedin.com/in/skalskip92/overlay/about-this-profile/))