-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample_images.py
More file actions
49 lines (37 loc) · 1.33 KB
/
sample_images.py
File metadata and controls
49 lines (37 loc) · 1.33 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import shutil
import os
import random
import argparse
CURRENT_DIR = os.getcwd()
OUTPUT_DIR = "input_images"
INPUT_DIR = "background_LSUI_input"
def sample_files(num_to_sample: int) -> None:
"""Sample some number of files randomly from an input directory to be labeled
Args:
total (int): number of files to pull from the input directory
"""
# define inputs
input_path = os.path.join(CURRENT_DIR, INPUT_DIR)
files_list = os.listdir(input_path)
assert num_to_sample <= len(
files_list
), "You are trying to sample more files than are present in your input directory, try lowering your sample quantity or changing your input directory."
# shuffle files list
random.shuffle(files_list)
# define outputs
output_dir = os.path.join(CURRENT_DIR, OUTPUT_DIR)
# move images
for path_i in range(num_to_sample):
# access original image
original_path = os.path.join(input_path, files_list[path_i])
# Move image to distribution folder
shutil.move(original_path, os.path.join(output_dir, files_list[path_i]))
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
"num_files",
help="total number of files to sample",
type=int,
)
args = parser.parse_args()
sample_files(args.num_files)