ultralytics / hub

Ultralytics HUB tutorials and support
https://hub.ultralytics.com
GNU Affero General Public License v3.0
136 stars 13 forks source link

YOLOv10 model using a custom YAML file #764

Open jamesparkskku opened 4 months ago

jamesparkskku commented 4 months ago

Search before asking

Question

Dear

I hope this message finds you well.

I am writing to inquire about the process of training a YOLOv10 model using a custom YAML file that I have created. I would appreciate it if you could provide me with detailed instructions or guidelines on how to properly configure and initiate the training process with my custom settings.

Specifically, I would like to understand the following:

The necessary steps to integrate my YAML file with YOLOv10. Any prerequisites or dependencies required before starting the training. Example commands or scripts that could help in launching the training process. Any additional tips or best practices for optimizing the training process using a custom configuration. Your assistance in this matter would be greatly appreciated as it will help streamline my workflow and ensure that the training process is conducted efficiently.

Thank you in advance for your support and guidance. I look forward to your response.

Best regards,

Parameters

nc: 1 # number of classes, 실제 클래스 수로 변경 scales: # model compound scaling constants x: [0.33, 0.50, 256] # [depth, width, max_channels]

YOLOv8.0n backbone

backbone:

YOLOv8.0n head

head:


import torch from ultralytics import YOLO import yaml

GPU 메모리 초기화

torch.cuda.empty_cache()

GPU 사용 여부 확인

device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') print(f'Using device: {device}')

data.yaml 파일 읽기

with open('C:/Users/user/yolov8_dataset/data.yaml', 'r') as file: data_config = yaml.safe_load(file)

데이터셋 경로 및 하이퍼파라미터 설정

train_path = data_config['train'] val_path = data_config['val'] batch_size = 1 # 배치 크기 더 줄이기 epochs = 1000 img_size = 256 # 이미지 크기 줄이기

모델 초기화

model = YOLO('C:/Users/user/yolov10-new.yaml')

모델을 GPU로 이동

model.model.to(device)

모델 훈련

model.train(data='C:/Users/user/yolov8_dataset/data.yaml', epochs=epochs, batch_size=batch_size, imgsz=img_size, device=device, verbose=True)

Additional

No response

github-actions[bot] commented 4 months ago

👋 Hello @jamesparkskku, thank you for raising an issue about Ultralytics HUB 🚀! Please visit our HUB Docs to learn more:

If this is a 🐛 Bug Report, please provide screenshots and steps to reproduce your problem to help us get started working on a fix.

If this is a ❓ Question, please provide as much information as possible, including dataset, model, environment details etc. so that we might provide the most helpful response.

We try to respond to all issues as promptly as possible. Thank you for your patience!

pderrenger commented 4 months ago

@jamesparkskku hello,

Thank you for reaching out and for your detailed inquiry! I'm glad to assist you with training a YOLOv10 model using your custom YAML file. Here are the steps and guidelines to help you get started:

Prerequisites and Dependencies

  1. Ensure you have the latest version of Ultralytics packages: Before proceeding, please verify that you are using the latest versions of the Ultralytics packages. You can update them using pip:

    pip install --upgrade ultralytics
  2. Dependencies: Make sure you have the necessary dependencies installed, including PyTorch and any other required libraries.

Integrating Your YAML File with YOLOv10

  1. Custom YAML File: Ensure your custom YAML file is correctly formatted and includes all necessary configurations. Your provided YAML file looks good for defining the model architecture.

  2. Data Configuration: Ensure your data.yaml file is correctly set up with paths to your training and validation datasets.

Example Commands and Scripts

Here is a step-by-step guide to initiate the training process using your custom settings:

  1. Initialize the Model: Use the YOLO class from the Ultralytics library to initialize your model with the custom YAML file.
  2. Train the Model: Use the train method to start the training process with your specified parameters.

Here is a complete example script based on your provided details:

import torch
from ultralytics import YOLO
import yaml

# Clear GPU memory
torch.cuda.empty_cache()

# Check if GPU is available
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
print(f'Using device: {device}')

# Read data.yaml file
with open('C:/Users/user/yolov8_dataset/data.yaml', 'r') as file:
    data_config = yaml.safe_load(file)

# Dataset paths and hyperparameters
train_path = data_config['train']
val_path = data_config['val']
batch_size = 1  # Reduce batch size if needed
epochs = 1000
img_size = 256  # Reduce image size if needed

# Initialize the model with custom YAML
model = YOLO('C:/Users/user/yolov10-new.yaml')

# Move model to GPU
model.model.to(device)

# Train the model
model.train(data='C:/Users/user/yolov8_dataset/data.yaml', epochs=epochs, batch_size=batch_size, imgsz=img_size, device=device, verbose=True)

Additional Tips and Best Practices

  1. Batch Size and Image Size: Adjust the batch size and image size based on your GPU memory capacity. Reducing these values can help if you encounter memory issues.
  2. Learning Rate and Optimizer: Experiment with different learning rates and optimizers to find the best settings for your specific dataset.
  3. Data Augmentation: Utilize data augmentation techniques to improve the robustness of your model.

For more detailed information and additional resources, please refer to the Ultralytics HUB documentation.

If you encounter any issues or have further questions, feel free to raise them here or join our Discord community for more interactive discussions.

github-actions[bot] commented 3 months 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 ⭐