ultralytics / ultralytics

NEW - YOLOv8 🚀 in PyTorch > ONNX > OpenVINO > CoreML > TFLite
https://docs.ultralytics.com
GNU Affero General Public License v3.0
28.3k stars 5.63k forks source link

Can I tune the rt-detr model? #14388

Open aluissp opened 2 months ago

aluissp commented 2 months ago

Search before asking

Question

Currently, I'm training the RT-DETR model on my own custom dataset. According to the documentation, there's a model.tune() method to optimize the hyperparameters. However, when I inspected the source code, this method runs a YOLO model instead of RT-DETR. I'm a little bit confused about it. Here's the code:

from ultralytics import RTDETR

# Load a COCO-pretrained RT-DETR-l model
model = RTDETR('rtdetr-l.pt')

model.tune(data='data.yaml', device=[0, 1], batch=8, epochs=40, iterations=35, imgsz=640)

Tune method:


def tune():
    ...
    return Tuner(args=args, _callbacks=self.callbacks)(model=self, iterations=iterations)

class Tuner:
    ...
    def __call__(self, model=None, iterations=10, cleanup=True):
                ...
                cmd = ["yolo", "train", *(f"{k}={v}" for k, v in train_args.items())]
                return_code = subprocess.run(cmd, check=True).returncode
                ckpt_file = weights_dir / ("best.pt" if (weights_dir / "best.pt").exists() else "last.pt")
                metrics = torch.load(ckpt_file)["train_metrics"]
                assert return_code == 0, "training failed"

Additional

No response

github-actions[bot] commented 2 months ago

👋 Hello @aluissp, thank you for your interest in Ultralytics YOLOv8 🚀! We recommend a visit to the Docs for new users where you can find many Python and CLI usage examples and where many of the most common questions may already be answered.

If this is a 🐛 Bug Report, please provide a minimum reproducible example to help us debug it.

If this is a custom training ❓ Question, please provide as much information as possible, including dataset image examples and training logs, and verify you are following our Tips for Best Training Results.

Join the vibrant Ultralytics Discord 🎧 community for real-time conversations and collaborations. This platform offers a perfect space to inquire, showcase your work, and connect with fellow Ultralytics users.

Install

Pip install the ultralytics package including all requirements in a Python>=3.8 environment with PyTorch>=1.8.

pip install ultralytics

Environments

YOLOv8 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):

Status

Ultralytics CI

If this badge is green, all Ultralytics CI tests are currently passing. CI tests verify correct operation of all YOLOv8 Modes and Tasks on macOS, Windows, and Ubuntu every 24 hours and on every commit.

Y-T-G commented 2 months ago

You can't.

glenn-jocher commented 2 months ago

@Y-T-G thank you for your question! Currently, the model.tune() method is designed for YOLO models and not specifically for RT-DETR models. As a result, it may not work as expected for RT-DETR.

For tuning RT-DETR models, you can manually adjust hyperparameters in the training script. Here's an example of how you can set custom hyperparameters:

from ultralytics import RTDETR

# Load a COCO-pretrained RT-DETR-l model
model = RTDETR('rtdetr-l.pt')

# Train the model with custom hyperparameters
results = model.train(
    data='data.yaml',
    epochs=40,
    batch=8,
    imgsz=640,
    device=[0, 1],
    lr0=0.01,  # initial learning rate
    momentum=0.937,  # momentum
    weight_decay=0.0005,  # weight decay
    ...
)

You can find more details on available hyperparameters in the Ultralytics documentation.

If you have any further questions or need additional assistance, feel free to ask! 😊

github-actions[bot] commented 1 month ago

👋 Hello there! We wanted to give you a friendly reminder that this issue has not had any recent activity and may be closed soon, but don't worry - you can always reopen it if needed. If you still have any questions or concerns, please feel free to let us know how we can help.

For additional resources and information, please see the links below:

Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed!

Thank you for your contributions to YOLO 🚀 and Vision AI ⭐