copy images and labels during forming dataset. add folder for corrupted labels, small refactor

This commit is contained in:
zxsanny
2024-08-13 01:57:42 +03:00
parent bb1dbfe1e7
commit 6b0a0e678e
4 changed files with 120 additions and 80 deletions
+41 -19
View File
@@ -6,25 +6,47 @@ from dto.imageLabel import ImageLabel
from preprocessing import read_labels
from matplotlib import pyplot as plt
from constants import datasets_dir, prefix
from constants import datasets_dir, prefix, processed_images_dir, processed_labels_dir
annotation_classes = AnnotationClass.read_json()
cur_dataset = os.path.join(datasets_dir, f'{prefix}2024-06-18', 'train')
images_dir = os.path.join(cur_dataset, 'images')
labels_dir = os.path.join(cur_dataset, 'labels')
for f in os.listdir(images_dir)[35247:]:
image_path = os.path.join(images_dir, f)
labels_path = os.path.join(labels_dir, f'{Path(f).stem}.txt')
img = ImageLabel(
image_path=image_path,
image=cv2.imread(image_path),
labels_path=labels_path,
labels=read_labels(labels_path)
)
img.visualize(annotation_classes)
print(f'visualizing {image_path}')
plt.close()
key = input('Press any key to continue')
def visualise_dataset():
cur_dataset = os.path.join(datasets_dir, f'{prefix}2024-06-18', 'train')
images_dir = os.path.join(cur_dataset, 'images')
labels_dir = os.path.join(cur_dataset, 'labels')
for f in os.listdir(images_dir)[35247:]:
image_path = os.path.join(images_dir, f)
labels_path = os.path.join(labels_dir, f'{Path(f).stem}.txt')
img = ImageLabel(
image_path=image_path,
image=cv2.imread(image_path),
labels_path=labels_path,
labels=read_labels(labels_path)
)
img.visualize(annotation_classes)
print(f'visualizing {image_path}')
plt.close()
key = input('Press any key to continue')
def visualise_processed_folder():
def show_image(img):
image_path = os.path.join(processed_images_dir, img)
labels_path = os.path.join(processed_labels_dir, f'{Path(img).stem}.txt')
img = ImageLabel(
image_path=image_path,
image=cv2.imread(image_path),
labels_path=labels_path,
labels=read_labels(labels_path)
)
img.visualize(annotation_classes)
images = os.listdir(processed_images_dir)
cur = 0
show_image(images[cur])
pass
if __name__ == '__main__':
visualise_processed_folder()