Skip to content
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

YOLOv10 model using a custom YAML file #764

Open
1 task done
jamesparkskku opened this issue Jul 10, 2024 · 2 comments
Open
1 task done

YOLOv10 model using a custom YAML file #764

jamesparkskku opened this issue Jul 10, 2024 · 2 comments
Labels
question A HUB question that does not involve a bug

Comments

@jamesparkskku
Copy link

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:

  • [-1, 1, Conv, [64, 3, 2]] # 최소 채널 수 64
  • [-1, 1, Conv, [128, 3, 2]] # 128
  • [-1, 3, C2f, [128, True]]
  • [-1, 1, Conv, [256, 3, 2]] # 256
  • [-1, 6, C2f, [256, True]]
  • [-1, 1, SCDown, [512, 3, 2]] # 512
  • [-1, 6, C2fCIB, [512, True]]
  • [-1, 1, SCDown, [1024, 3, 2]] # 1024
  • [-1, 3, C2fCIB, [1024, True]]
  • [-1, 1, SPPF, [1024, 5]] # 1024
  • [-1, 1, PSA, [1024]] # 1024

YOLOv8.0n head

head:

  • [-1, 1, nn.Upsample, [None, 2, "nearest"]]

  • [[-1, 6], 1, Concat, [1]]

  • [-1, 2, C2fCIB, [512, True]] # 512

  • [-1, 1, C3TR, [512, 8, 4, 512]]

  • [-1, 1, nn.Upsample, [None, 2, "nearest"]]

  • [[-1, 4], 1, Concat, [1]]

  • [-1, 2, C2fCIB, [256, True]] # 256

  • [-1, 1, C3TR, [256, 8, 4, 256]]

  • [-1, 1, Conv, [256, 3, 2]]

  • [[-1, 13], 1, Concat, [1]]

  • [-1, 2, C2fCIB, [512, True]] # 512

  • [-1, 1, C3TR, [512, 8, 4, 512]]

  • [-1, 1, SCDown, [512, 3, 2]]

  • [[-1, 10], 1, Concat, [1]]

  • [-1, 3, C2fCIB, [1024, True]] # 1024

  • [-1, 1, C3TR, [1024, 8, 4, 1024]]

  • [[16, 19, 22], 1, v10Detect, [nc]]


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

@jamesparkskku jamesparkskku added the question A HUB question that does not involve a bug label Jul 10, 2024
Copy link

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

  • Quickstart. Start training and deploying YOLO models with HUB in seconds.
  • Datasets: Preparing and Uploading. Learn how to prepare and upload your datasets to HUB in YOLO format.
  • Projects: Creating and Managing. Group your models into projects for improved organization.
  • Models: Training and Exporting. Train YOLOv5 and YOLOv8 models on your custom datasets and export them to various formats for deployment.
  • Integrations. Explore different integration options for your trained models, such as TensorFlow, ONNX, OpenVINO, CoreML, and PaddlePaddle.
  • Ultralytics HUB App. Learn about the Ultralytics App for iOS and Android, which allows you to run models directly on your mobile device.
    • iOS. Learn about YOLO CoreML models accelerated on Apple's Neural Engine on iPhones and iPads.
    • Android. Explore TFLite acceleration on mobile devices.
  • Inference API. Understand how to use the Inference API for running your trained models in the cloud to generate predictions.

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
Copy link
Member

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question A HUB question that does not involve a bug
Projects
None yet
Development

No branches or pull requests

2 participants