콘텐츠로 건너뛰기

머신 러닝 모범 사례 및 모델 학습을 위한 팁

소개

컴퓨터 비전 프로젝트를 진행할 때 가장 중요한 단계 중 하나는 모델 훈련입니다. 이 단계에 도달하기 전에 목표를 정의하고 데이터를 수집하고 주석을 달아야 합니다. 데이터가 깨끗하고 일관성이 있는지 확인하기 위해 데이터를 전처리한 후에는 모델 훈련으로 넘어갈 수 있습니다.



Watch: Model Training Tips | How to Handle Large Datasets | Batch Size, GPU Utilization and Mixed Precision

그렇다면 모델 트레이닝이란 무엇인가요? 모델 트레이닝은 모델이 시각적 패턴을 인식하고 데이터를 기반으로 예측하도록 가르치는 프로세스입니다. 이는 애플리케이션의 성능과 정확도에 직접적인 영향을 미칩니다. 이 가이드에서는 컴퓨터 비전 모델을 효과적으로 훈련하는 데 도움이 되는 모범 사례, 최적화 기술 및 문제 해결 팁을 다룹니다.

How to Train a Machine Learning Model

컴퓨터 비전 모델은 오류를 최소화하기 위해 내부 매개변수를 조정하여 학습합니다. 처음에는 모델에 라벨이 지정된 대규모 이미지 세트가 제공됩니다. 이 이미지에 무엇이 있는지 예측하고 예측을 실제 라벨이나 내용과 비교하여 오차를 계산합니다. 이러한 오차는 모델의 예측이 실제 값과 얼마나 차이가 나는지를 보여줍니다.

During training, the model iteratively makes predictions, calculates errors, and updates its parameters through a process called backpropagation. In this process, the model adjusts its internal parameters (weights and biases) to reduce the errors. By repeating this cycle many times, the model gradually improves its accuracy. Over time, it learns to recognize complex patterns such as shapes, colors, and textures.

역전파란 무엇인가요?

This learning process makes it possible for the computer vision model to perform various tasks, including object detection, instance segmentation, and image classification. The ultimate goal is to create a model that can generalize its learning to new, unseen images so that it can accurately understand visual data in real-world applications.

이제 모델을 훈련할 때 뒤에서 어떤 일이 일어나는지 알았으니 모델을 훈련할 때 고려해야 할 사항을 살펴보겠습니다.

대규모 데이터 세트에 대한 교육

대규모 데이터 세트를 사용하여 모델을 학습시키려는 경우 고려해야 할 몇 가지 측면이 있습니다. 예를 들어 배치 크기를 조정하고, GPU 활용도를 제어하고, 멀티스케일 학습을 사용하도록 선택할 수 있습니다. 이러한 각 옵션을 자세히 살펴보겠습니다.

배치 크기 및 GPU 활용도

대규모 데이터 세트에서 모델을 학습할 때는 GPU 을 효율적으로 활용하는 것이 중요합니다. 배치 크기는 중요한 요소입니다. 배치 크기는 머신러닝 모델이 한 번의 훈련 반복에서 처리하는 데이터 샘플의 수입니다. GPU 에서 지원하는 최대 배치 크기를 사용하면 기능을 최대한 활용하고 모델 학습에 걸리는 시간을 줄일 수 있습니다. 하지만 GPU 메모리가 부족해지지 않도록 주의해야 합니다. 메모리 오류가 발생하면 모델이 원활하게 학습할 때까지 배치 크기를 점진적으로 줄이세요.

With respect to YOLO11, you can set the batch_size 매개변수의 교육 구성 를 GPU 용량에 맞게 설정하세요. 또한 batch=-1 in your training script will automatically determine the batch size that can be efficiently processed based on your device's capabilities. By fine-tuning the batch size, you can make the most of your GPU resources and improve the overall training process.

하위 집합 교육

하위 집합 학습은 더 큰 데이터 집합을 나타내는 작은 데이터 집합으로 모델을 학습시키는 현명한 전략입니다. 특히 초기 모델 개발 및 테스트 중에 시간과 리소스를 절약할 수 있습니다. 시간이 부족하거나 다양한 모델 구성을 실험하는 경우 하위 집합 학습이 좋은 옵션입니다.

When it comes to YOLO11, you can easily implement subset training by using the fraction 매개변수를 설정합니다. 이 매개변수를 사용하면 데이터 세트의 어느 부분을 학습에 사용할지 지정할 수 있습니다. 예를 들어, 설정 fraction=0.1 는 데이터의 10%에 대해 모델을 학습시킵니다. 전체 데이터 집합을 사용하여 모델을 학습시키기 전에 이 기술을 사용하여 빠르게 반복하고 모델을 튜닝할 수 있습니다. 하위 집합 학습은 빠른 진행을 돕고 잠재적인 문제를 조기에 식별하는 데 도움이 됩니다.

다중 규모 교육

멀티스케일 트레이닝은 다양한 크기의 이미지로 모델을 훈련하여 일반화 능력을 향상시키는 기술입니다. 모델은 다양한 규모와 거리에서 물체를 감지하는 방법을 학습하여 더욱 강력해질 수 있습니다.

For example, when you train YOLO11, you can enable multiscale training by setting the scale 매개변수를 설정합니다. 이 매개변수는 훈련 이미지의 크기를 지정된 계수만큼 조정하여 다양한 거리에 있는 물체를 시뮬레이션합니다. 예를 들어 scale=0.5 은 이미지 크기를 절반으로 줄이고 scale=2.0 로 설정하면 두 배가 됩니다. 이 매개변수를 구성하면 모델이 다양한 이미지 배율을 경험하고 다양한 객체 크기와 시나리오에서 감지 기능을 향상시킬 수 있습니다.

캐싱

캐싱은 머신러닝 모델 학습의 효율성을 향상시키는 중요한 기술입니다. 캐싱은 사전 처리된 이미지를 메모리에 저장함으로써 GPU 에서 디스크에서 데이터가 로드되기를 기다리는 시간을 줄여줍니다. 모델은 디스크 I/O 작업으로 인한 지연 없이 지속적으로 데이터를 수신할 수 있습니다.

Caching can be controlled when training YOLO11 using the cache 매개변수입니다:

  • cache=True: 데이터 세트 이미지를 RAM에 저장하여 가장 빠른 액세스 속도를 제공하지만 메모리 사용량이 증가합니다.
  • cache='disk': 이미지를 디스크에 저장하며, RAM보다는 느리지만 매번 새 데이터를 로드하는 것보다 빠릅니다.
  • cache=False: 캐싱을 비활성화하여 가장 느린 옵션인 디스크 I/O에만 의존합니다.

혼합 정밀 교육

Mixed precision training uses both 16-bit (FP16) and 32-bit (FP32) floating-point types. The strengths of both FP16 and FP32 are leveraged by using FP16 for faster computation and FP32 to maintain precision where needed. Most of the neural network's operations are done in FP16 to benefit from faster computation and lower memory usage. However, a master copy of the model's weights is kept in FP32 to ensure accuracy during the weight update steps. You can handle larger models or larger batch sizes within the same hardware constraints.

혼합 정밀 교육 개요

To implement mixed precision training, you'll need to modify your training scripts and ensure your hardware (like GPUs) supports it. Many modern deep learning frameworks, such as Tensorflow, offer built-in support for mixed precision.

Mixed precision training is straightforward when working with YOLO11. You can use the amp 플래그를 설정합니다. 설정 amp=True 를 사용하면 자동 혼합 정밀도(AMP) 훈련이 가능합니다. 혼합 정밀도 훈련은 모델 훈련 프로세스를 최적화하는 간단하면서도 효과적인 방법입니다.

사전 학습된 가중치

Using pretrained weights is a smart way to speed up your model's training process. Pretrained weights come from models already trained on large datasets, giving your model a head start. Transfer learning adapts pretrained models to new, related tasks. Fine-tuning a pre-trained model involves starting with these weights and then continuing training on your specific dataset. This method of training results in faster training times and often better performance because the model starts with a solid understanding of basic features.

그리고 pretrained parameter makes transfer learning easy with YOLO11. Setting pretrained=True 는 기본 사전 학습된 가중치를 사용하거나 사용자 지정 사전 학습된 모델의 경로를 지정할 수 있습니다. 사전 학습된 가중치와 전이 학습을 사용하면 모델의 기능을 효과적으로 향상시키고 학습 비용을 절감할 수 있습니다.

대규모 데이터 집합을 처리할 때 고려해야 할 기타 기술

대규모 데이터 집합을 처리할 때 고려해야 할 몇 가지 다른 기술이 있습니다:

  • Learning Rate Schedulers: Implementing learning rate schedulers dynamically adjusts the learning rate during training. A well-tuned learning rate can prevent the model from overshooting minima and improve stability. When training YOLO11, the lrf 매개변수를 사용하면 최종 학습률을 초기 학습률의 일부분으로 설정하여 학습률 스케줄을 관리할 수 있습니다.
  • 분산 훈련: 대규모 데이터 세트를 처리할 때 분산 훈련은 판도를 바꿀 수 있습니다. 트레이닝 워크로드를 여러 GPU 또는 머신에 분산하여 트레이닝 시간을 단축할 수 있습니다.

훈련할 에포크 수

모델을 학습할 때 에포크는 전체 학습 데이터 세트를 한 번 완전히 통과하는 것을 의미합니다. 에포크 동안 모델은 학습 세트의 각 예시를 한 번 처리하고 학습 알고리즘에 따라 매개 변수를 업데이트합니다. 일반적으로 모델이 시간이 지남에 따라 파라미터를 학습하고 개선하려면 여러 개의 에포크가 필요합니다.

A common question that comes up is how to determine the number of epochs to train the model for. A good starting point is 300 epochs. If the model overfits early, you can reduce the number of epochs. If overfitting does not occur after 300 epochs, you can extend the training to 600, 1200, or more epochs.

However, the ideal number of epochs can vary based on your dataset's size and project goals. Larger datasets might require more epochs for the model to learn effectively, while smaller datasets might need fewer epochs to avoid overfitting. With respect to YOLO11, you can set the epochs 매개변수를 설정합니다.

조기 중지

조기 중지는 모델 학습을 최적화하는 데 유용한 기술입니다. 유효성 검사 성능을 모니터링하여 모델 개선이 중단되면 훈련을 중단할 수 있습니다. 계산 리소스를 절약하고 과적합을 방지할 수 있습니다.

The process involves setting a patience parameter that determines how many epochs to wait for an improvement in validation metrics before stopping training. If the model's performance does not improve within these epochs, training is stopped to avoid wasting time and resources.

조기 종료 개요

For YOLO11, you can enable early stopping by setting the patience parameter in your training configuration. For example, patience=5 는 5회 연속으로 유효성 검사 지표가 개선되지 않으면 트레이닝이 중단됨을 의미합니다. 이 방법을 사용하면 트레이닝 프로세스가 효율적으로 유지되고 과도한 계산 없이 최적의 성능을 달성할 수 있습니다.

클라우드 교육과 로컬 교육 중 선택

모델 트레이닝에는 클라우드 트레이닝과 로컬 트레이닝의 두 가지 옵션이 있습니다.

클라우드 트레이닝은 확장성과 강력한 하드웨어를 제공하며 대규모 데이터 세트와 복잡한 모델을 처리하는 데 이상적입니다. Google Cloud, AWS, Azure와 같은 플랫폼은 고성능 GPU와 TPU에 대한 온디맨드 액세스를 제공하여 트레이닝 시간을 단축하고 대규모 모델을 실험할 수 있도록 지원합니다. 하지만 클라우드 트레이닝은 특히 장기간에 걸쳐 비용이 많이 들 수 있으며 데이터 전송으로 인해 비용과 지연 시간이 늘어날 수 있습니다.

로컬 교육을 통해 제어 및 사용자 지정 기능을 강화하여 특정 요구 사항에 맞게 환경을 조정하고 지속적인 클라우드 비용을 피할 수 있습니다. 장기 프로젝트에 더 경제적일 수 있으며 데이터가 온프레미스에 유지되므로 더 안전합니다. 하지만 로컬 하드웨어에는 리소스 제한이 있고 유지 관리가 필요할 수 있으므로 대규모 모델의 경우 교육 시간이 길어질 수 있습니다.

최적화 도구 선택

An optimizer is an algorithm that adjusts the weights of your neural network to minimize the loss function, which measures how well the model is performing. In simpler terms, the optimizer helps the model learn by tweaking its parameters to reduce errors. Choosing the right optimizer directly affects how quickly and accurately the model learns.

최적화 도구 매개변수를 미세 조정하여 모델 성능을 개선할 수도 있습니다. 학습 속도를 조정하면 매개변수를 업데이트할 때 단계의 크기가 설정됩니다. 안정성을 위해 적당한 학습 속도로 시작하여 시간이 지남에 따라 점차적으로 학습 속도를 낮추어 장기적인 학습을 개선할 수 있습니다. 또한 모멘텀을 설정하면 과거 업데이트가 현재 업데이트에 얼마나 영향을 미치는지 결정할 수 있습니다. 모멘텀의 일반적인 값은 약 0.9입니다. 이 값은 일반적으로 적절한 균형을 제공합니다.

일반적인 최적화 도구

최적화 도구마다 다양한 장단점이 있습니다. 몇 가지 일반적인 최적화 도구에 대해 간략히 살펴보겠습니다.

  • SGD(확률적 그라데이션 하강):

    • 매개변수에 대한 손실 함수의 기울기를 사용하여 모델 매개변수를 업데이트합니다.
    • 간단하고 효율적이지만 수렴 속도가 느리고 로컬 최소값에 갇힐 수 있습니다.
  • 아담(적응형 순간 추정):

    • SGD와 모멘텀 및 RMSProp의 장점을 결합합니다.
    • 기울기의 첫 번째 및 두 번째 모멘트의 추정치를 기반으로 각 파라미터의 학습 속도를 조정합니다.
    • 노이즈가 많은 데이터와 희박한 그라데이션에 적합합니다.
    • Efficient and generally requires less tuning, making it a recommended optimizer for YOLO11.
  • RMSProp(루트 평균 제곱 전파):

    • 기울기를 최근 기울기의 크기 평균으로 나누어 각 매개변수에 대한 학습 속도를 조정합니다.
    • Helps in handling the vanishing gradient problem and is effective for recurrent neural networks.

For YOLO11, the optimizer 파라미터를 사용하면 SGD, Adam, AdamW, NAdam, RAdam, RMSProp 등 다양한 최적화 도구 중에서 선택하거나 다음과 같이 설정할 수 있습니다. auto 를 클릭하여 모델 구성에 따라 자동으로 선택할 수 있습니다.

커뮤니티와 연결하기

컴퓨터 비전 애호가 커뮤니티의 일원이 되면 문제를 해결하고 더 빨리 배우는 데 도움이 될 수 있습니다. 다음은 연결하고, 도움을 받고, 아이디어를 공유하는 몇 가지 방법입니다.

커뮤니티 리소스

  • GitHub Issues: Visit the YOLO11 GitHub repository and use the Issues tab to ask questions, report bugs, and suggest new features. The community and maintainers are very active and ready to help.
  • Ultralytics 디스코드 서버: Ultralytics Discord 서버에 가입하여 다른 사용자 및 개발자와 채팅하고, 지원을 받고, 경험을 공유하세요.

공식 문서

  • Ultralytics YOLO11 Documentation: Check out the official YOLO11 documentation for detailed guides and helpful tips on various computer vision projects.

이러한 리소스를 사용하면 문제를 해결하고 컴퓨터 비전 커뮤니티의 최신 트렌드와 사례를 최신 상태로 유지하는 데 도움이 됩니다.

주요 내용

Training computer vision models involves following good practices, optimizing your strategies, and solving problems as they arise. Techniques like adjusting batch sizes, mixed precision training, and starting with pre-trained weights can make your models work better and train faster. Methods like subset training and early stopping help you save time and resources. Staying connected with the community and keeping up with new trends will help you keep improving your model training skills.

자주 묻는 질문

Ultralytics YOLO 로 대규모 데이터 집합을 학습할 때 GPU 활용도를 높이려면 어떻게 해야 하나요?

GPU 활용도를 높이려면 batch_size parameter in your training configuration to the maximum size supported by your GPU. This ensures that you make full use of the GPU's capabilities, reducing training time. If you encounter memory errors, incrementally reduce the batch size until training runs smoothly. For YOLO11, setting batch=-1 를 교육 스크립트에 추가하면 효율적인 처리를 위한 최적의 배치 크기가 자동으로 결정됩니다. 자세한 내용은 교육 구성.

What is mixed precision training, and how do I enable it in YOLO11?

Mixed precision training utilizes both 16-bit (FP16) and 32-bit (FP32) floating-point types to balance computational speed and precision. This approach speeds up training and reduces memory usage without sacrificing model accuracy. To enable mixed precision training in YOLO11, set the amp 매개변수를 True 을 트레이닝 구성에 추가합니다. 이렇게 하면 자동 혼합 정밀도(AMP) 훈련이 활성화됩니다. 이 최적화 기법에 대한 자세한 내용은 교육 구성.

How does multiscale training enhance YOLO11 model performance?

Multiscale training enhances model performance by training on images of varying sizes, allowing the model to better generalize across different scales and distances. In YOLO11, you can enable multiscale training by setting the scale 매개변수를 설정할 수 있습니다. 예를 들어 scale=0.5 은 이미지 크기를 절반으로 줄이고 scale=2.0 를 두 배로 늘립니다. 이 기술은 다양한 거리에 있는 물체를 시뮬레이션하여 다양한 시나리오에서 모델을 더욱 강력하게 만듭니다. 설정 및 자세한 내용은 교육 구성.

How can I use pre-trained weights to speed up training in YOLO11?

Using pre-trained weights can significantly reduce training times and improve model performance by starting from a model that already understands basic features. In YOLO11, you can set the pretrained 매개변수를 True 를 선택하거나 학습 구성에서 미리 학습된 사용자 지정 가중치에 대한 경로를 지정할 수 있습니다. 전이 학습이라고 하는 이 접근 방식은 대규모 데이터 세트의 지식을 활용하여 특정 작업에 맞게 조정합니다. 사전 학습된 가중치와 그 장점에 대해 자세히 알아보기 여기.

The number of epochs refers to the complete passes through the training dataset during model training. A typical starting point is 300 epochs. If your model overfits early, you can reduce the number. Alternatively, if overfitting isn't observed, you might extend training to 600, 1200, or more epochs. To set this in YOLO11, use the epochs 매개변수를 설정하세요. 이상적인 에포크 수를 결정하는 방법에 대한 추가 도움말은 다음 섹션을 참조하세요. 에포크 수.

📅 Created 3 months ago ✏️ Updated 4 days ago

댓글