AzureML์์์ Ultralytics YOLOv5 ๐ ํต์คํํธ#
Microsoft Azure Machine Learning(AzureML)์ ์ํ Ultralytics YOLOv5 ๋น ๋ฅธ ์์ ๊ฐ์ด๋์ ์ค์ ๊ฒ์ ํ์ํฉ๋๋ค! ์ด ๊ฐ์ด๋์์๋ ๊ฐ์ ํ๊ฒฝ ์์ฑ๋ถํฐ ๋ชจ๋ธ ํ์ต ๋ฐ ์ถ๋ก ์คํ์ ์ด๋ฅด๊ธฐ๊น์ง ๋ชจ๋ ๊ณผ์ ์ ๋ค๋ฃจ๋ฉฐ, AzureML ์ฐ์ฐ ์ธ์คํด์ค์์ YOLOv5๋ฅผ ์ค์ ํ๋ ๋ฐฉ๋ฒ์ ์๋ดํฉ๋๋ค.
Azure๋ ๋ฌด์์ธ๊ฐ์?#
Azure๋ Microsoft์ ํฌ๊ด์ ์ธ cloud computing ํ๋ซํผ์ ๋๋ค. ์ฐ์ฐ ๋ฅ๋ ฅ, ๋ฐ์ดํฐ๋ฒ ์ด์ค, ๋ถ์ ๋๊ตฌ, machine learning ๊ธฐ๋ฅ ๋ฐ ๋คํธ์ํน ์๋ฃจ์ ์ ํฌํจํ ๋ฐฉ๋ํ ์๋น์ค ๋ฐฐ์ด์ ์ ๊ณตํฉ๋๋ค. Azure๋ ์กฐ์ง์ด Microsoft์์ ๊ด๋ฆฌํ๋ ๋ฐ์ดํฐ ์ผํฐ๋ฅผ ํตํด ์ ํ๋ฆฌ์ผ์ด์ ๊ณผ ์๋น์ค๋ฅผ ๊ตฌ์ถ, ๋ฐฐํฌ ๋ฐ ๊ด๋ฆฌํ ์ ์๋๋ก ์ง์ํ๋ฉฐ, ์จํ๋ ๋ฏธ์ค ์ธํ๋ผ์์ ํด๋ผ์ฐ๋๋ก์ ์ํฌ๋ก๋ ๋ง์ด๊ทธ๋ ์ด์ ์ ์ฉ์ดํ๊ฒ ํฉ๋๋ค.
Azure Machine Learning(AzureML)์ด๋ ๋ฌด์์ธ๊ฐ์?#
Azure Machine Learning(AzureML)์ ๋จธ์ ๋ฌ๋ ๋ชจ๋ธ์ ๊ฐ๋ฐ, ํ์ต, ๋ฐฐํฌ๋ฅผ ์ํด ์ค๊ณ๋ ํนํ๋ ํด๋ผ์ฐ๋ ์๋น์ค์ ๋๋ค. ๋ชจ๋ ์์ค์ ๋ฐ์ดํฐ ๊ณผํ์์ ๊ฐ๋ฐ์์๊ฒ ์ ํฉํ ๋๊ตฌ๊ฐ ํฌํจ๋ ํ์ ํ๊ฒฝ์ ์ ๊ณตํฉ๋๋ค. ์ฃผ์ ๊ธฐ๋ฅ์๋ automated machine learning (AutoML), ๋ชจ๋ธ ์์ฑ์ ์ํ ๋๋๊ทธ์ค๋๋กญ ์ธํฐํ์ด์ค, ๊ทธ๋ฆฌ๊ณ ML ๋ผ์ดํ์ฌ์ดํด์ ๋ํ ๋์ฑ ์ธ๋ฐํ ์ ์ด๋ฅผ ์ํ ๊ฐ๋ ฅํ Python SDK๊ฐ ํฌํจ๋ฉ๋๋ค. AzureML์ predictive modeling์ ์ ํ๋ฆฌ์ผ์ด์ ์ ๋ด์ฅํ๋ ํ๋ก์ธ์ค๋ฅผ ๋จ์ํํฉ๋๋ค.
์ฌ์ ์๊ตฌ ์ฌํญ#
์ด ๊ฐ์ด๋๋ฅผ ๋ฐ๋ฅด๋ ค๋ฉด ํ์ฑํ๋ Azure subscription๊ณผ AzureML workspace์ ๋ํ ์ก์ธ์ค ๊ถํ์ด ํ์ํฉ๋๋ค. ์ํฌ์คํ์ด์ค๊ฐ ์ค์ ๋์ด ์์ง ์๋ค๋ฉด ๊ณต์ Azure documentation์์ฐธ์กฐํ์ฌ ์์ฑํด ์ฃผ์ธ์.
์ปดํจํ ์ธ์คํด์ค ์์ฑ#
AzureML์ ์ปดํจํ ์ธ์คํด์ค๋ ๋ฐ์ดํฐ ๊ณผํ์๋ฅผ ์ํ ๊ด๋ฆฌํ ํด๋ผ์ฐ๋ ๊ธฐ๋ฐ ์ํฌ์คํ ์ด์ ์ ์ ๊ณตํฉ๋๋ค.
- AzureML ์์ ์์ญ์ผ๋ก ์ด๋ํฉ๋๋ค.
- ์ผ์ชฝ ์ฐฝ์์ **Compute(์ปดํจํ )**๋ฅผ ์ ํํฉ๋๋ค.
- Compute instances(์ปดํจํ ์ธ์คํด์ค) ํญ์ผ๋ก ์ด๋ํ์ฌ **New(์๋ก ๋ง๋ค๊ธฐ)**๋ฅผ ํด๋ฆญํฉ๋๋ค.
- ํ์ต ๋๋ ์ถ๋ก ์๊ตฌ์ฌํญ์ ๋ฐ๋ผ ์ ์ ํ CPU ๋๋ GPU ๋ฆฌ์์ค๋ฅผ ์ ํํ์ฌ ์ธ์คํด์ค๋ฅผ ๊ตฌ์ฑํ์ธ์.
ํฐ๋ฏธ๋ ์ด๊ธฐ#
์ปดํจํ ์ธ์คํด์ค๊ฐ ์คํ๋๋ฉด AzureML ์คํ๋์ค์์ ์ง์ ํด๋น ํฐ๋ฏธ๋์ ์ก์ธ์คํ ์ ์์ต๋๋ค.
- ์ผ์ชฝ ์ฐฝ์ Notebooks(๋ ธํธ๋ถ) ์น์ ์ผ๋ก ์ด๋ํฉ๋๋ค.
- ์๋จ ๋๋กญ๋ค์ด ๋ฉ๋ด์์ ์ปดํจํ ์ธ์คํด์ค๋ฅผ ์ฐพ์ต๋๋ค.
- ํ์ผ ๋ธ๋ผ์ฐ์ ์๋์ Terminal(ํฐ๋ฏธ๋) ์ต์ ์ ํด๋ฆญํ์ฌ ์ธ์คํด์ค์ ๋ํ ๋ช ๋ น์ค ์ธํฐํ์ด์ค๋ฅผ ์ฝ๋๋ค.

YOLOv5 ์ค์ ๋ฐ ์คํ#
์ด์ ํ๊ฒฝ์ ์ค์ ํ๊ณ Ultralytics YOLOv5๋ฅผ ์คํํด ๋ณด๊ฒ ์ต๋๋ค.
๊ฐ์ ํ๊ฒฝ ์์ฑ#
์ข ์์ฑ์ ๊ด๋ฆฌํ๊ธฐ ์ํด ๊ฐ์ ํ๊ฒฝ์ ์ฌ์ฉํ๋ ๊ฒ์ด ๋ชจ๋ฒ ์ฌ๋ก์ ๋๋ค. AzureML ์ฐ์ฐ ์ธ์คํด์ค์ ์ฌ์ ์ค์น๋ Conda๋ฅผ ์ฌ์ฉํ๊ฒ ์ต๋๋ค. ์์ธํ Conda ์ค์ ๊ฐ์ด๋๋ Ultralytics Conda Quickstart Guide๋ฅผ ์ฐธ์กฐํ์ธ์.
ํน์ Python ๋ฒ์ ์ ์ฌ์ฉํ์ฌ Conda ํ๊ฒฝ(์: yolov5env)์ ๋ง๋ค๊ณ ํ์ฑํํฉ๋๋ค:
conda create --name yolov5env -y python=3.10 # Create a new Conda environment
conda activate yolov5env # Activate the environment
conda install pip -y # Ensure pip is installedYOLOv5 ์ ์ฅ์ ๋ณต์ #
Git์ ์ฌ์ฉํ์ฌ GitHub์์ ๊ณต์ Ultralytics YOLOv5 ๋ฆฌํฌ์งํ ๋ฆฌ๋ฅผ ๋ณต์ ํฉ๋๋ค:
git clone https://github.com/ultralytics/yolov5 # Clone the repository
cd yolov5 # Navigate into the directory
# Initialize submodules (if any, though YOLOv5 typically doesn't require this step)
# git submodule update --init --recursive์ข ์์ฑ ์ค์น#
requirements.txt ํ์ผ์ ๋์ด๋ ํ์ Python ํจํค์ง๋ฅผ ์ค์นํฉ๋๋ค. ๋ชจ๋ธ ๋ด๋ณด๋ด๊ธฐ ๊ธฐ๋ฅ์ ์ํด ONNX๋ ์ค์นํฉ๋๋ค.
pip install -r requirements.txt # Install core dependencies
pip install "onnx>=1.12.0" # Install ONNX for exportingYOLOv5 ์์ ์ํ#
์ค์ ์ด ์๋ฃ๋์์ผ๋ฏ๋ก ์ด์ YOLOv5 ๋ชจ๋ธ์ ํ์ต, ๊ฒ์ฆ, ์ถ๋ก ๋ฐ ๋ด๋ณด๋ด๊ธฐํ ์ ์์ต๋๋ค.
-
COCO128๊ณผ ๊ฐ์ ๋ฐ์ดํฐ์ ์ผ๋ก ๋ชจ๋ธ์ **ํ์ต(Train)**ํฉ๋๋ค. ์์ธํ ๋ด์ฉ์ Training Mode ๋ฌธ์๋ฅผ ํ์ธํ์ธ์.
# Start training using yolov5s pretrained weights on the COCO128 dataset python train.py --data coco128.yaml --weights yolov5s.pt --img 640 --epochs 10 --batch 16 -
Precision, Recall, mAP ๋ฑ์ ์งํ๋ฅผ ์ฌ์ฉํ์ฌ ํ์ต๋ ๋ชจ๋ธ์ ์ฑ๋ฅ์ **๊ฒ์ฆ(Validate)**ํฉ๋๋ค. ์ต์ ์ ๋ํ ๋ด์ฉ์ Validation Mode ๊ฐ์ด๋๋ฅผ ์ฐธ์กฐํ์ธ์.
# Validate the yolov5s model on the COCO128 validation set python val.py --weights yolov5s.pt --data coco128.yaml --img 640 -
์๋ก์ด ์ด๋ฏธ์ง๋ ๋น๋์ค์ ๋ํด **์ถ๋ก ์ ์คํ(Run Inference)**ํฉ๋๋ค. ๋ค์ํ ์ถ๋ก ์์ค์ ๋ํด์๋ Prediction Mode ๋ฌธ์๋ฅผ ์ดํด๋ณด์ธ์.
# Run inference with yolov5s on sample images python detect.py --weights yolov5s.pt --source data/images --img 640 -
๋ฐฐํฌ๋ฅผ ์ํด ๋ชจ๋ธ์ ONNX, TensorRT ๋๋ CoreML๊ณผ ๊ฐ์ ๋ค์ํ ํ์์ผ๋ก ๋ด๋ณด๋ ๋๋ค(Export). Export Mode ๊ฐ์ด๋์ ONNX Integration ํ์ด์ง๋ฅผ ์ฐธ์กฐํ์ธ์.
# Export yolov5s to ONNX format python export.py --weights yolov5s.pt --include onnx --img 640
๋ ธํธ๋ถ ์ฌ์ฉํ๊ธฐ#
๋ํํ ํ๊ฒฝ์ ์ ํธํ๋ ๊ฒฝ์ฐ AzureML Notebook ๋ด์์ ์ด๋ฌํ ๋ช ๋ น์ ์คํํ ์ ์์ต๋๋ค. Conda ํ๊ฒฝ์ ์ฐ๊ฒฐ๋ ์ฌ์ฉ์ ์ง์ IPython kernel์ ์์ฑํด์ผ ํฉ๋๋ค.
์ IPython ์ปค๋ ์์ฑ#
์ปดํจํ ์ธ์คํด์ค ํฐ๋ฏธ๋์์ ๋ค์ ๋ช ๋ น์ ์คํํฉ๋๋ค:
# Ensure your Conda environment is active
# conda activate yolov5env
# Install ipykernel if not already present
conda install ipykernel -y
# Create a new kernel linked to your environment
python -m ipykernel install --user --name yolov5env --display-name "Python (yolov5env)"์ปค๋์ ์์ฑํ ํ ๋ธ๋ผ์ฐ์ ๋ฅผ ์๋ก๊ณ ์นจํ์ธ์. .ipynb ๋
ธํธ๋ถ ํ์ผ์ ์ด๊ฑฐ๋ ๋ง๋ค ๋, ์ฐ์ธก ์๋จ์ ์ปค๋ ๋๋กญ๋ค์ด ๋ฉ๋ด์์ ์ ์ปค๋("Python (yolov5env)")์ ์ ํํ์ธ์.
๋ ธํธ๋ถ ์ ์์ ๋ช ๋ น ์คํ#
-
Python ์ : Python ์ ์ ์ฝ๋๋ ์ ํํ
yolov5env์ปค๋์ ์ฌ์ฉํ์ฌ ์๋์ผ๋ก ์คํ๋ฉ๋๋ค. -
Bash ์ : ์ ๋ช ๋ น์ ์คํํ๋ ค๋ฉด ์ ์์ ๋ถ๋ถ์
%%bash๋งค์ง ๋ช ๋ น์ ์ฌ์ฉํ์ธ์. ๋ ธํธ๋ถ์ ์ปค๋ ํ๊ฒฝ ์ปจํ ์คํธ๋ฅผ ์๋์ผ๋ก ์์ํ์ง ์์ผ๋ฏ๋ก, ๊ฐ bash ์ ๋ด์์ Conda ํ๊ฒฝ์ ํ์ฑํํด์ผ ํฉ๋๋ค.%%bash source activate yolov5env # Activate environment within the cell # Example: Run validation using the activated environment python val.py --weights yolov5s.pt --data coco128.yaml --img 640
์ถํํฉ๋๋ค! AzureML์์ Ultralytics YOLOv5๋ฅผ ์ฑ๊ณต์ ์ผ๋ก ์ค์ ํ๊ณ ์คํํ์ต๋๋ค. ์ถ๊ฐ ํ์์ ์ํด ๋ค๋ฅธ Ultralytics Integrations ๋๋ ์์ธํ YOLOv5 documentation์ ํ์ธํด ๋ณด์ธ์. ๋ถ์ฐ ํ์ต์ด๋ ์๋ํฌ์ธํธ๋ก์์ ๋ชจ๋ธ ๋ฐฐํฌ์ ๊ฐ์ ๊ณ ๊ธ ์๋๋ฆฌ์ค์ ๊ฒฝ์ฐ AzureML documentation๋ ์ ์ฉํ ๊ฒ์ ๋๋ค.