File size: 1,433 Bytes
d34bf36
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import os


image_folder = r'E:\NLP\CoMoGAN\duplicate-images\FOD\FOD\clear_Images'
annotation_folder = r'E:\NLP\CoMoGAN\duplicate-images\FOD\FOD\Annotations'

image_files = set(os.path.splitext(f)[0] for f in os.listdir(image_folder) if f.endswith('.png'))
annotation_files = set(os.path.splitext(f)[0] for f in os.listdir(annotation_folder) if f.endswith('.xml'))
print(f"Số lượng ảnh ban đầu: {len(image_files)}")
print(f"Số lượng annotation ban đầu: {len(annotation_files)}")
annotations_to_remove = annotation_files - image_files
for annotation in annotations_to_remove:
    annotation_path = os.path.join(annotation_folder, annotation + '.xml')
    os.remove(annotation_path)
    print(f"Đã xoá: {annotation_path}")
print(f"Số lượng annotation đã xóa: {len(annotations_to_remove)}")
remaining_annotations = annotation_files - annotations_to_remove
print(f"Số lượng annotation còn lại: {len(remaining_annotations)}")
mismatched_annotations = [annotation for annotation in remaining_annotations if annotation not in image_files]

if mismatched_annotations:
    print("Có sự không khớp giữa tên ảnh và annotation còn lại:")
    for mismatch in mismatched_annotations:
        print(f"Annotation không khớp: {mismatch}.xml")
else:
    print("Tất cả các annotation còn lại đều khớp với tên ảnh.")

print("Quá trình hoàn tất!")