!git clone https://github.com/SkalskiP/yolov9.git
%cd yolov9
!grep -v '^torch' requirements.txt > temp_requirements.txt
!pip install -r temp_requirements.txt -q
!pip install torch==2.3.1 torchvision==0.18.1 torchaudio==2.3.1 --index-url https://download.pytorch.org/whl/cu121
import os
HOME = os.getcwd()
print(HOME)
!wget -P {HOME}/weights -q https://github.com/WongKinYiu/yolov9/releases/download/v0.1/yolov9-c.pt
!wget -P {HOME}/weights -q https://github.com/WongKinYiu/yolov9/releases/download/v0.1/yolov9-e.pt
!wget -P {HOME}/weights -q https://github.com/WongKinYiu/yolov9/releases/download/v0.1/gelan-c.pt
!wget -P {HOME}/weights -q https://github.com/WongKinYiu/yolov9/releases/download/v0.1/gelan-e.pt
!python detect.py --weights yolov5s.pt --img 640 --conf 0.25 --source /content/yolo.jpg
img_path = "/content/yolo.jpg" # 정확한 경로!
import os
# 경로 탐색
result_dir = "/content/yolov5/runs/detect"
for root, dirs, files in os.walk(result_dir):
for file in files:
print(os.path.join(root, file))
import torch
from PIL import Image
import matplotlib.pyplot as plt
# YOLOv5 모델 로드
model = torch.hub.load('ultralytics/yolov5', 'yolov5s', pretrained=True)
# 이미지 로드
img_path = '/content/yolo.jpg' # 이미지 경로
img = Image.open(img_path)
# 객체 감지
results = model(img)
# 결과 시각화
results.show() # 이미지 새 창 또는 Colab에서 바로 표시
!unzip -qq "/content/football-players-detection.v14i.yolov9.zip"
# 실제 학습에서는 10 epoch 이상, loss converge 체크, --device 0 (GPU 있을 시)
!python train.py \
--batch 16 --epochs 10 --img 640 --device 0 --min-items 0 --close-mosaic 15 \
--data data.yaml \
--weights weights/gelan-c.pt \
--cfg models/detect/gelan-c.yaml \
--hyp hyp.scratch-high.yaml
from IPython.display import Image
Image(filename=f"./runs/train/exp/results.png", width=1000)
!python val.py \
--img 640 --batch 32 --conf 0.001 --iou 0.7 --device 0 \
--data ./data.yaml \
--weights ./runs/train/exp/weights/best.pt
!python detect.py \
--img 1280 --conf 0.1 --device 0 \
--weights ./runs/train/exp/weights/best.pt \
--source ./test/images
import glob
from IPython.display import Image, display
for image_path in glob.glob(f'./runs/detect/exp2/*.jpg')[:2]:
display(Image(filename=image_path, width=600))