| 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!") | |