forked from pprp/SimpleCVReproduction
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsample_10.py
31 lines (22 loc) · 782 Bytes
/
sample_10.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
29
30
31
import os
import shutil
import numpy as np
import random
from os.path import join
save_path = "./dpjsamplecrop"
image_root_dir = r"D:\GitHub\voc2007_for_yolo_torch\images"
label_root_dir = r"D:\GitHub\voc2007_for_yolo_torch\labels"
fo = open("dpj_train.txt", "w")
for ids in os.listdir(image_root_dir):
print("ids:%s" % ids)
dir_image = os.path.join(image_root_dir, ids)
dir_label = os.path.join(label_root_dir, ids)
print(len(os.listdir(dir_image)))
selected = random.sample(os.listdir(dir_image), 8)
print(selected)
for s in selected:
fo.write(join(save_path, s)+"\n")
shutil.copy(join(dir_image, s), join(save_path, s))
s = s.replace("jpg", 'txt')
shutil.copy(join(dir_label, s), join(save_path, s))
fo.close()