add checkpoints and config system

convert from bbox oriented and pascal xml
fixes
This commit is contained in:
Alex Bezdieniezhnykh
2024-06-18 21:32:15 +03:00
parent b7b8b8fd27
commit 66987f4d95
6 changed files with 182 additions and 59 deletions
+25 -4
View File
@@ -4,11 +4,10 @@ import shutil
from datetime import datetime
from pathlib import Path
from ultralytics import YOLOv10
from constants import current_images_dir, current_labels_dir, annotation_classes
from constants import current_images_dir, current_labels_dir, annotation_classes, prefix, date_format
prefix = 'zombobase-'
latest_model = f'models/{prefix}latest.pt'
today_folder = f'{prefix}{datetime.now():%Y-%m-%d}'
today_folder = f'{prefix}{datetime.now():{date_format}}'
train_set = 70
valid_set = 20
test_set = 10
@@ -38,13 +37,35 @@ def move_annotations(images, folder):
image_path = path.join(current_images_dir, image_name)
label_name = f'{Path(image_name).stem}.txt'
label_path = path.join(current_labels_dir, label_name)
if not path.exists(label_path):
if not check_label(label_path):
remove(image_path)
else:
replace(image_path, path.join(destination_images, image_name))
replace(label_path, path.join(destination_labels, label_name))
def check_label(label_path):
lines_edited = False
if not path.exists(label_path):
return False
with open(label_path, 'r') as f:
lines = f.readlines()
for line in lines:
for val in line.split(' ')[1:]:
if float(val) > 1:
lines.remove(line)
lines_edited = True
if len(lines) == 0:
return False
if not lines_edited:
return True
with open(label_path, 'w') as label_write:
label_write.writelines(lines)
label_write.close()
return True
def create_yaml():
lines = ['names:']
for c in annotation_classes: