์ฝ˜ํ…์ธ ๋กœ ๊ฑด๋„ˆ๋›ฐ๊ธฐ

๋งˆ์Šคํ„ฐํ•˜๊ธฐ YOLOv5 ๐Ÿš€ ๊ตฌ๊ธ€ ํด๋ผ์šฐ๋“œ ํ”Œ๋žซํผ(GCP) ๋”ฅ๋Ÿฌ๋‹ ๊ฐ€์ƒ ๋จธ์‹ (VM)์— ๋ฐฐํฌ โญ

Embarking on the journey of artificial intelligence and machine learning can be exhilarating, especially when you leverage the power and flexibility of a cloud platform. Google Cloud Platform (GCP) offers robust tools tailored for machine learning enthusiasts and professionals alike. One such tool is the Deep Learning VM that is preconfigured for data science and ML tasks. In this tutorial, we will navigate through the process of setting up YOLOv5 on a GCP Deep Learning VM. Whether you're taking your first steps in ML or you're a seasoned practitioner, this guide is designed to provide you with a clear pathway to implementing object detection models powered by YOLOv5.

๐Ÿ†“ Plus, if you're a fresh GCP user, you're in luck with a $300 free credit offer to kickstart your projects.

GCP ์™ธ์—๋„ ๋‹ค์Œ๊ณผ ๊ฐ™์ด YOLOv5 ์— ์•ก์„ธ์Šคํ•  ์ˆ˜ ์žˆ๋Š” ๋‹ค๋ฅธ ๋น ๋ฅธ ์‹œ์ž‘ ์˜ต์…˜์„ ์‚ดํŽด๋ณด์„ธ์š”. Colab ๋…ธํŠธ๋ถ ์ฝœ๋žฉ์—์„œ ์—ด๊ธฐ ์˜ ํ™•์žฅ์„ฑ ๋˜๋Š” ๋ธŒ๋ผ์šฐ์ € ๊ธฐ๋ฐ˜ ๊ฒฝํ—˜์„ ์œ„ํ•ด Amazon AWS. ๋˜ํ•œ ์ปจํ…Œ์ด๋„ˆ ์• ํ˜ธ๊ฐ€๋Š” ๋‹ค์Œ์—์„œ ๊ณต์‹ Docker ์ด๋ฏธ์ง€๋ฅผ ํ™œ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋„์ปค ํ—ˆ๋ธŒ ๋„์ปค ํ’€ ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์บก์Šํ™”๋œ ํ™˜๊ฒฝ์„ ๋งŒ๋“ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

1๋‹จ๊ณ„: ๋”ฅ ๋Ÿฌ๋‹ ๊ฐ€์ƒ ๋จธ์‹  ์ƒ์„ฑ ๋ฐ ๊ตฌ์„ฑ

Let's begin by creating a virtual machine that's tuned for deep learning:

  1. GCP ๋งˆ์ผ“ํ”Œ๋ ˆ์ด์Šค๋กœ ์ด๋™ํ•˜์—ฌ ๋”ฅ ๋Ÿฌ๋‹ VM์„ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค.
  2. n1 ํ‘œ์ค€-8 ์ธ์Šคํ„ด์Šค๋ฅผ ์„ ํƒํ•˜๋ฉด 8๊ฐœ์˜ vCPU์™€ 30GB ๋ฉ”๋ชจ๋ฆฌ๊ฐ€ ๊ท ํ˜• ์žˆ๊ฒŒ ์ œ๊ณต๋˜๋ฏ€๋กœ ์ €ํฌ์˜ ์š”๊ตฌ ์‚ฌํ•ญ์— ์ด์ƒ์ ์ž…๋‹ˆ๋‹ค.
  3. ๋‹ค์Œ์œผ๋กœ GPU๋ฅผ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค. ์ด๋Š” ์›Œํฌ๋กœ๋“œ์— ๋”ฐ๋ผ ๋‹ค๋ฅด๋ฉฐ, Tesla T4์™€ ๊ฐ™์€ ๊ธฐ๋ณธ GPU๋ผ๋„ ๋ชจ๋ธ ํ•™์Šต ์†๋„๋ฅผ ํ˜„์ €ํžˆ ๋†’์—ฌ์ค๋‹ˆ๋‹ค.
  4. ๋ฒˆ๊ฑฐ๋กœ์›€ ์—†์ด ์„ค์ •ํ•˜๋ ค๋ฉด '์ฒ˜์Œ ์‹œ์ž‘ํ•  ๋•Œ NVIDIA GPU ๋“œ๋ผ์ด๋ฒ„๋ฅผ ์ž๋™์œผ๋กœ ์„ค์น˜ํ•˜์‹œ๊ฒ ์Šต๋‹ˆ๊นŒ?"๋ผ๋Š” ํ™•์ธ๋ž€์„ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค.
  5. 300GB SSD ์˜๊ตฌ ๋””์Šคํฌ๋ฅผ ํ• ๋‹นํ•˜์—ฌ I/O ์ž‘์—…์— ๋ณ‘๋ชฉ ํ˜„์ƒ์ด ๋ฐœ์ƒํ•˜์ง€ ์•Š๋„๋ก ํ•˜์„ธ์š”.
  6. '๋ฐฐํฌ'๋ฅผ ๋ˆ„๋ฅด๋ฉด GCP๊ฐ€ ๋งž์ถคํ˜• ๋”ฅ ๋Ÿฌ๋‹ ๊ฐ€์ƒ ๋จธ์‹ ์„ ํ”„๋กœ๋น„์ €๋‹ํ•˜๋Š” ๋งˆ๋ฒ•์„ ๋ถ€๋ฆฝ๋‹ˆ๋‹ค.

์ด ๊ฐ€์ƒ ๋จธ์‹ ์—๋Š” YOLOv5 ์— ํ•„์š”ํ•œ ๋ชจ๋“  ์ข…์†์„ฑ์„ ํŽธ๋ฆฌํ•˜๊ฒŒ ๋ฒˆ๋“ค๋กœ ์ œ๊ณตํ•˜๋Š” Anaconda Python ๋ฐฐํฌ๋ฅผ ํฌํ•จํ•˜์—ฌ ์‚ฌ์ „ ์„ค์น˜๋œ ๋‹ค์–‘ํ•œ ๋„๊ตฌ์™€ ํ”„๋ ˆ์ž„์›Œํฌ๊ฐ€ ํฌํ•จ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.

๋”ฅ ๋Ÿฌ๋‹ ๊ฐ€์ƒ ๋จธ์‹ ์„ ์„ค์ •ํ•˜๋Š” GCP ๋งˆ์ผ“ํ”Œ๋ ˆ์ด์Šค ๊ทธ๋ฆผ

2๋‹จ๊ณ„: ๋‹ค์Œ ์šฉ๋„์˜ VM ์ค€๋น„ YOLOv5

ํ™˜๊ฒฝ ์„ค์ •์ด ์™„๋ฃŒ๋˜๋ฉด YOLOv5 ์„ ์‹คํ–‰ํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค:

# Clone the YOLOv5 repository
git clone https://github.com/ultralytics/yolov5

# Change the directory to the cloned repository
cd yolov5

# Install the necessary Python packages from requirements.txt
pip install -r requirements.txt

์ด ์„ค์ • ํ”„๋กœ์„ธ์Šค๋ฅผ ํ†ตํ•ด Python ํ™˜๊ฒฝ ๋ฒ„์ „ 3.8.0 ์ด์ƒ ๋ฐ PyTorch 1.8 ์ด์ƒ์—์„œ ์ž‘์—…ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์Šคํฌ๋ฆฝํŠธ๋Š” ์ตœ์‹  YOLOv5 ๋ฆด๋ฆฌ์Šค์—์„œ ๋ Œ๋”๋ง๋˜๋Š” ๋ชจ๋ธ๊ณผ ๋ฐ์ดํ„ฐ ์„ธํŠธ๋ฅผ ์›ํ™œํ•˜๊ฒŒ ๋‹ค์šด๋กœ๋“œํ•˜๋ฏ€๋กœ ๋ฒˆ๊ฑฐ๋กœ์›€ ์—†์ด ๋ชจ๋ธ ํ•™์Šต์„ ์‹œ์ž‘ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

3๋‹จ๊ณ„: YOLOv5 ๋ชจ๋ธ ๊ต์œก ๋ฐ ๋ฐฐํฌ ๐ŸŒ

์„ค์ •์ด ์™„๋ฃŒ๋˜๋ฉด GCP VM์—์„œ YOLOv5 ์„ ์‚ฌ์šฉํ•˜์—ฌ ๊ต์œก ๋ฐ ์ถ”๋ก ์„ ์‹œ์ž‘ํ•  ์ค€๋น„๊ฐ€ ๋œ ๊ฒƒ์ž…๋‹ˆ๋‹ค:

# Train a model on your data
python train.py

# Validate the trained model for Precision, Recall, and mAP
python val.py --weights yolov5s.pt

# Run inference using the trained model on your images or videos
python detect.py --weights yolov5s.pt --source path/to/images

# Export the trained model to other formats for deployment
python export.py --weights yolov5s.pt --include onnx coreml tflite

YOLOv5 ์—์„œ ๋ช‡ ๊ฐ€์ง€ ๋ช…๋ น๋งŒ์œผ๋กœ ํŠน์ • ์š”๊ตฌ์— ๋งž๋Š” ๋งž์ถคํ˜• ๊ฐ์ฒด ๊ฐ์ง€ ๋ชจ๋ธ์„ ํ•™์Šต์‹œํ‚ค๊ฑฐ๋‚˜ ์‚ฌ์ „ ํ•™์Šต๋œ ๊ฐ€์ค‘์น˜๋ฅผ ํ™œ์šฉํ•˜์—ฌ ๋‹ค์–‘ํ•œ ์ž‘์—…์—์„œ ๋น ๋ฅธ ๊ฒฐ๊ณผ๋ฅผ ์–ป์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

GCP ๋”ฅ ๋Ÿฌ๋‹ VM์—์„œ ๋ชจ๋ธ ํ•™์Šต์„ ๋ณด์—ฌ์ฃผ๋Š” ํ„ฐ๋ฏธ๋„ ๋ช…๋ น ์ด๋ฏธ์ง€

์Šค์™‘ ๊ณต๊ฐ„ ํ• ๋‹น(์„ ํƒ ์‚ฌํ•ญ)

๋Œ€์šฉ๋Ÿ‰ ๋ฐ์ดํ„ฐ ์„ธํŠธ๋ฅผ ์ฒ˜๋ฆฌํ•˜๋Š” ๊ฒฝ์šฐ, 64GB์˜ ์ถ”๊ฐ€ ์Šค์™‘ ๋ฉ”๋ชจ๋ฆฌ๋กœ GCP ์ธ์Šคํ„ด์Šค๋ฅผ ์ฆํญํ•˜๋Š” ๊ฒƒ์„ ๊ณ ๋ คํ•˜์„ธ์š”:

sudo fallocate -l 64G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
free -h  # confirm the memory increment

๊ฒฐ๋ก 

์ถ•ํ•˜ํ•ฉ๋‹ˆ๋‹ค! ์ด์ œ YOLOv5 ์˜ ๊ธฐ๋Šฅ๊ณผ ๊ตฌ๊ธ€ ํด๋ผ์šฐ๋“œ ํ”Œ๋žซํผ์˜ ๊ณ„์‚ฐ ๋Šฅ๋ ฅ์„ ํ™œ์šฉํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ์ด ์กฐํ•ฉ์€ ๋ฌผ์ฒด ๊ฐ์ง€ ์ž‘์—…์— ํ™•์žฅ์„ฑ, ํšจ์œจ์„ฑ, ๋‹ค์šฉ๋„์„ฑ์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. ๊ฐœ์ธ ํ”„๋กœ์ ํŠธ, ํ•™์ˆ  ์—ฐ๊ตฌ, ์‚ฐ์—… ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋“ฑ ์–ด๋–ค ๋ถ„์•ผ์—์„œ๋“  ํด๋ผ์šฐ๋“œ์—์„œ AI์™€ ๋จธ์‹  ๋Ÿฌ๋‹์˜ ์„ธ๊ณ„๋กœ ์ค‘์š”ํ•œ ๋ฐœ๊ฑธ์Œ์„ ๋‚ด๋””๋Ž ์Šต๋‹ˆ๋‹ค.

์—ฌ์ •์„ ๋ฌธ์„œํ™”ํ•˜๊ณ , Ultralytics ์ปค๋ฎค๋‹ˆํ‹ฐ์™€ ์ธ์‚ฌ์ดํŠธ๋ฅผ ๊ณต์œ ํ•˜๋ฉฐ, GitHub ํ† ๋ก ๊ณผ ๊ฐ™์€ ํ˜‘์—…์˜ ์žฅ์„ ํ™œ์šฉํ•˜์—ฌ ๋”์šฑ ์„ฑ์žฅํ•˜๋Š” ๊ฒƒ์„ ์žŠ์ง€ ๋งˆ์„ธ์š”. ์ด์ œ YOLOv5 ๋ฐ GCP์™€ ํ•จ๊ป˜ ํ˜์‹ ์„ ์‹œ์ž‘ํ•˜์„ธ์š”! ๐ŸŒŸ

ML ๊ธฐ์ˆ ๊ณผ ์ง€์‹์„ ๊ณ„์† ํ–ฅ์ƒ์‹œํ‚ค๊ณ  ์‹ถ์œผ์‹ ๊ฐ€์š”? ์„ค๋ช…์„œ ๋ฐ ํŠœํ† ๋ฆฌ์–ผ์„ ํ†ตํ•ด ๋” ๋งŽ์€ ๋ฆฌ์†Œ์Šค๋ฅผ ์‚ดํŽด๋ณด์„ธ์š”. AI ๋ชจํ—˜์„ ๊ณ„์†ํ•˜์„ธ์š”!



Created 2023-11-12, Updated 2024-06-02
Authors: glenn-jocher (5), Burhan-Q (1)

๋Œ“๊ธ€