-
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rtdetr weight problem #12663
Comments
👋 Hello @S-7-12, 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. InstallPip install the pip install ultralytics EnvironmentsYOLOv8 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):
StatusIf 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. |
Hello! For training RT-DETR models with ResNet backbones, pre-trained weights might not be directly available from the Ultralytics repository. You can utilize pre-trained ResNet models from PyTorch repository as an alternative. Here's a code snippet on how you can do this: import torch
from ultralytics import YOLO
# Load RT-DETR model and specify the backbone
model = YOLO('rtdetr.yaml', backbone='resnet50') # Change to 'resnet101' as needed
# Load pre-trained weights from PyTorch
pretrained_weights = torch.load('resnet50.pth') # Adjust path and filename as necessary
model.load_state_dict(pretrained_weights, strict=False)
# Continue with your training setup Replace |
Traceback (most recent call last): |
I noticed that the rtdetr r-50.yaml file already exists in the ultralytics repository and can be trained that way, but the weighting issue is still not resolved. |
Hi there! It's great to see that you've found the appropriate For training with pre-trained ResNet weights, you'll have to load these weights manually before the training starts. Here's a simple way to do it using PyTorch: import torch
from ultralytics import RTDETR
# Load the RTDETR model configuration
model = RTDETR('ultralytics/cfg/models/rt-detr/rtdetr-resnet50.yaml')
# Load pre-trained weights
weights = torch.load('path_to_resnet50_weights.pth')
model.model.load_state_dict(weights, strict=False)
# Train the model
model.train(data='path_to_coco128.yaml', epochs=100) Make sure to replace |
@glenn-jocher ,hi, the pre-trained ResNet weights cannot be loaded correctly, as the parameter names of pre-trained ResNet models from PyTorch repository is consistent with backbone defined in rtdetr r-50.yaml of ultralytics repository. How to resolve this issue? |
#12663 (comment) |
@S-7-12 hi! Thanks for pointing out the issue with loading the backbone weights. It seems like the parameter names in the pre-trained ResNet model might not match directly with those expected by the RT-DETR model configuration. To resolve this, you can map the ResNet weights to the expected names in the RT-DETR model. Here’s a quick way to adapt the weights: import torch
from ultralytics import RTDETR
# Load the RTDETR model configuration
model = RTDETR('ultralytics/cfg/models/rt-detr/rtdetr-resnet50.yaml')
# Load pre-trained weights
resnet_weights = torch.load('path_to_resnet50_weights.pth')
adapted_weights = {k if 'backbone' in k else 'backbone.' + k: v for k, v in resnet_weights.items()}
# Load adapted weights into the model, ignoring incompatible keys
model.model.load_state_dict(adapted_weights, strict=False)
# Now you can proceed with training
model.train(data='path_to_coco128.yaml', epochs=100) This script prepends 'backbone.' to the keys of the ResNet weights, aligning them with the expected format in the RT-DETR model. Adjust the string manipulation as necessary based on the exact mismatch pattern. Let me know if this helps or if you need further adjustments! 😊 |
``> @S-7-12 hi! Thanks for pointing out the issue with loading the backbone weights. It seems like the parameter names in the pre-trained ResNet model might not match directly with those expected by the RT-DETR model configuration. To resolve this, you can map the ResNet weights to the expected names in the RT-DETR model.
import warnings
import torch
warnings.filterwarnings('ignore')
from ultralytics import RTDETR
# Load RT-DETR model and specify the backbone
model = RTDETR('ultralytics/cfg/models/rt-detr/rtdetr-resnet101.yaml') # Change to 'resnet101' as needed
# Display model information (optional)
# Train the model on the COCO8 example dataset for 100 epochs
model.train(data='/home/rendoudou/swx/pycharm/v5-ours/yolov5-master/data/our.yaml',
imgsz=640,
cache=False,
epochs=300,
pretrained='resnet101.pth',
batch=16,
device='1',
project='runs-test/rtdetr-r101-train',
name='rtdetr-ours-',
patience=30,
) Thanks, I found out that I can introduce weights this way, the code is currently running with no error messages, do you see any errors in the code? |
Hey @S-7-12-12! Glad to hear that you've managed to get your code running smoothly! 🚀 From the snippet you've shared, everything looks in order. Just ensure that the path to your dataset and the pretrained weights are correctly specified. Also, keep an eye on the device configuration to match your available hardware. If any issues arise during training or if you need further assistance, feel free to reach out. Happy training! 😊 |
Search before asking
Question
For the rtdetr model, I would like to train the model using the backbones of resnet50 and 101, but have not found the corresponding pre-training weights.
Additional
no
The text was updated successfully, but these errors were encountered: