forked from Harry24k/adversarial-attacks-pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilter_labels.py
28 lines (21 loc) · 1.07 KB
/
filter_labels.py
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
import os
import shutil
import argparse
def copy_labels(images_dir, labels_dir, output_dir):
if not os.path.exists(output_dir):
os.makedirs(output_dir)
image_files = [f for f in os.listdir(images_dir) if os.path.isfile(os.path.join(images_dir, f))]
for image_file in image_files:
label_file = os.path.splitext(image_file)[0] + '.txt'
label_path = os.path.join(labels_dir, label_file)
if os.path.exists(label_path):
shutil.copy(label_path, os.path.join(output_dir, label_file))
else:
print(f"Label for {image_file} not found.")
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Copy labels for images to a new directory.")
parser.add_argument("--images_dir", help="Directory containing the images.")
parser.add_argument("--labels_dir", help="Directory containing the labels.")
parser.add_argument("--output_dir", help="Directory to save the copied labels.")
args = parser.parse_args()
copy_labels(args.images_dir, args.labels_dir, args.output_dir)