| | import os
|
| |
|
| |
|
| | folder_path = "kohya_finetune_data"
|
| |
|
| |
|
| | image_extensions = ('.png', '.jpg', '.jpeg')
|
| |
|
| |
|
| | image_files = [f for f in os.listdir(folder_path) if f.lower().endswith(image_extensions)]
|
| | text_files = [f for f in os.listdir(folder_path) if f.endswith('.txt')]
|
| |
|
| |
|
| | image_basenames = {os.path.splitext(f)[0] for f in image_files}
|
| | text_basenames = {os.path.splitext(f)[0] for f in text_files}
|
| |
|
| |
|
| | for image_file in image_files:
|
| | base_name = os.path.splitext(image_file)[0]
|
| | if base_name not in text_basenames:
|
| | os.remove(os.path.join(folder_path, image_file))
|
| | print(f'Removed image file without corresponding text file: {image_file}')
|
| |
|
| |
|
| | for text_file in text_files:
|
| | base_name = os.path.splitext(text_file)[0]
|
| | if base_name not in image_basenames:
|
| | os.remove(os.path.join(folder_path, text_file))
|
| | print(f'Removed text file without corresponding image file: {text_file}')
|
| |
|