Installing Ubuntu 20.04 LTS and running YOLOv4 and YOLOv5 on it.
Документация
git clone https://github.com/ultralytics/yolov5.git
cd yolov5
pip install -r requirements.txt
# скачает нейронку и начнет распознавать
python3 detect.py --weights yolov5m.pt --source 1
Чтобы обучить сеть надо подговить исходные данные
<?php
`rm -rf res`;
`mkdir -m 0777 res`;
`mkdir -m 0777 res/train`;
`mkdir -m 0777 res/train/images`;
`mkdir -m 0777 res/train/annotations`;
`mkdir -m 0777 res/valid`;
`mkdir -m 0777 res/valid/images`;
`mkdir -m 0777 res/valid/annotations`;
`mkdir -m 0777 res/test`;
`mkdir -m 0777 res/test/images`;
`mkdir -m 0777 res/test/annotations`;
$start = microtime(true);
$copied = 0;
$files = glob('images/*.jpg');
$files_with_annotations = [];
foreach ($files as $key => $value) {
$name = str_replace(".jpg", ".txt", $value);
$name = str_replace("images/", "annotations/", $name);
if (file_exists($name)) {
$files_with_annotations[] = $value;
}
}
shuffle($files_with_annotations);
$count_files = count($files_with_annotations);
$res_folder = "train";
foreach ($files_with_annotations as $key => $value) {
$name = str_replace(".jpg", "", $value);
$name = str_replace("images/", "", $name);
$txt_name = __DIR__ . "/annotations/{$name}.txt";
if (intval($count_files * 0.7) < $key) {
$res_folder = "valid";
}
if (intval($count_files * 0.9) < $key) {
$res_folder = "test";
}
copy("images/{$name}.jpg", "res/$res_folder/images/{$name}.jpg");
copy("annotations/{$name}.txt", "res/$res_folder/annotations/{$name}.txt");
$copied++;
}
$start -= microtime(true);
print("\n\n copied $copied , took time $start\n\n");