!git clone https://github.com/ultralytics/yolov5
%cd yolov5
!pip install -r requirements.txt
!pip install roboflow
from roboflow import Roboflow
rf = Roboflow(api_key="3Qm4mMrKJ3ziqeMABVyI")
project = rf.workspace("project-fyk0c").project("collection-box")
dataset = project.version(2).download("yolov5")
%mv collection-box-2/ dataset
import yaml
# Update the paths in the YAML file to match the new directory structure
with open('dataset/data.yaml', 'r') as f:
data = yaml.safe_load(f)
# Set the paths directly to the respective directories
data['train'] = 'dataset/train/images'
data['val'] = 'dataset/valid/images'
# If you have a test set, uncomment the following line
# data['test'] = 'dataset/test/images'
with open('dataset/data.yaml', 'w') as f:
yaml.dump(data, f)
# Verify the updated data
print(data)
!python train.py --img 640 --batch 16 --epochs 50 --data dataset/data.yaml --cfg models/yolov5s.yaml --weights yolov5s.pt --name yolov5s_results