mirror of
https://github.com/azaion/ai-training.git
synced 2026-04-22 11:06:35 +00:00
fix augmentation - correct bboxes to be within borders+margin
Add classes = 80 as default number in yaml file
This commit is contained in:
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user