1.6.3

roboflow/rf-detr1.6.3Apr 2, 2026by Borda

AI Summary

This release introduces convenient features for easier annotation and training, including the direct retrieval of source images in predictions and automatic detection of class counts. It also addresses critical bug fixes regarding ONNX export integrity, CUDA context handling in multi-GPU setups, and deployment file handling.

Key Highlights

  • The `predict()` method now returns the original source image and its shape within `detections.data` for easier annotation.
  • The `RFDETR.train()` method automatically detects the number of classes from the dataset directory when not explicitly set.
  • The `optimize_for_inference()` method now accepts dtype as a string (e.g., 'float16') in addition to torch types.
  • Fixed ONNX export to correctly preserve class counts after fine-tuning by replacing `nn.Linear` modules in-place.
  • Fixed `deploy_to_roboflow` raising `FileNotFoundError` by ensuring `class_names.txt` is written to the upload directory.

New Features

  • Source image and shape retrieval in `predict()` outputs.
  • Automatic `num_classes` inference during training.
  • String dtype support for `optimize_for_inference()`.

Full Release Notes

## 🌱 Changed

- **`predict()` returns source image and shape on detections.** Returned `sv.Detections` objects now include `detections.data["source_image"]` (the original image as a NumPy array) and `detections.data["source_shape"]` (a `(height, width)` tuple), so you can annotate results without loading the image separately. (#892)

    ```python
    detections = model.predict("https://media.roboflow.com/dog.jpg", threshold=0.5)
    annotated = sv.BoxAnnotator().annotate(detections.data["source_image"], detections)
    ```

- **`RFDETR.train()` auto-detects `num_classes` from the dataset.** When `num_classes` is not explicitly set, RF-DETR reads the class count from the dataset directory and reinitializes the detection head automatically. A warning is emitted when your configured value differs from the dataset count. (#893)

    ```python
    model = RFDETRSmall()
    model.train(dataset_dir="./dataset")  # num_classes inferred from dataset
    ```

- **`optimize_for_inference()` accepts dtype as a string.** Pass `"float16"` or `"bfloat16"` in addition to `torch.float16`; invalid inputs now raise `TypeError` uniformly. (#899)

## 🔧 Fixed

- Fixed fine-tuned models exporting wrong class counts to ONNX: `reinitialize_detection_head` now replaces `nn.Linear` modules instead of mutating tensor data in-place, keeping `out_features` consistent with the actual weight shape after fine-tuning. (#904)
- Fixed `optimize_for_inference()` leaking a CUDA context on multi-GPU setups — deep-copy, export, and JIT-trace now run inside the correct device context. Also fixed: state is rolled back cleanly if optimization fails mid-way, and temp download files now use unique per-process paths to prevent parallel worker collisions. (#899)
- Fixed `deploy_to_roboflow` raising `FileNotFoundError` after PyTorch Lightning migration — `class_names.txt` is now written to the upload directory and `args.class_names` is populated before saving the checkpoint, restoring uploads for all model types including segmentation. (#890)

---

## 🏆 Contributors

Welcome to our new contributors, and thank you to everyone who helped with this release:

- **Md Faruk Alam** (@farukalamai) ([LinkedIn](https://www.linkedin.com/in/farukalamai/)) — *predict source image and shape*
- **Jirka Borovec** (@Borda) ([LinkedIn](https://www.linkedin.com/in/jirka-borovec/)) — *release coordination, reviews*

*Automated contributions: @copilot-swe-agent[bot], @pre-commit-ci[bot]*

---

**Full changelog**: https://github.com/roboflow/rf-detr/compare/1.6.2...1.6.3