fix augmentation - correct bboxes to be within borders+margin

Add classes = 80 as default number in yaml file
This commit is contained in:
zxsanny
2024-09-24 12:56:05 +03:00
parent 42ea4ebc2f
commit c234e8b190
9 changed files with 178 additions and 78 deletions
+9 -9
View File
@@ -4,8 +4,6 @@ import xml.etree.cElementTree as et
from pathlib import Path
import cv2
labels_dir = 'labels'
images_dir = 'images'
tag_size = 'size'
tag_object = 'object'
@@ -17,9 +15,11 @@ default_class = 1
image_extensions = ['jpg', 'png', 'jpeg']
def convert(folder, read_annotations, ann_format):
os.makedirs(images_dir, exist_ok=True)
os.makedirs(labels_dir, exist_ok=True)
def convert(folder, dest_folder, read_annotations, ann_format):
dest_images_dir = os.path.join(dest_folder, 'images')
dest_labels_dir = os.path.join(dest_folder, 'labels')
os.makedirs(dest_images_dir, exist_ok=True)
os.makedirs(dest_labels_dir, exist_ok=True)
for f in os.listdir(folder):
if not f[-3:] in image_extensions:
@@ -39,8 +39,8 @@ def convert(folder, read_annotations, ann_format):
except Exception as e:
print(f'Error conversion for {f}. Error: {e}')
shutil.copy(os.path.join(folder, f), os.path.join(images_dir, f))
with open(os.path.join(labels_dir, f'{Path(label).stem}.txt'), 'w') as new_label_file:
shutil.copy(os.path.join(folder, f), os.path.join(dest_images_dir, f))
with open(os.path.join(dest_labels_dir, f'{Path(label).stem}.txt'), 'w') as new_label_file:
new_label_file.writelines(lines)
new_label_file.close()
print(f'Image {f} has been processed successfully')
@@ -115,5 +115,5 @@ def rename_images(folder):
if __name__ == '__main__':
convert('datasets/others/UAVHeightImages', read_bbox_oriented, 'txt')
convert('datasets/others/UAVimages', read_pascal_voc, 'xml')
convert('/azaion/datasets/others/cars_height', '/azaion/datasets/converted', read_bbox_oriented, 'txt')
convert('/azaion/datasets/others/cars', '/azaion/datasets/converted', read_pascal_voc, 'xml')