Spaces:
Build error
Build error
Create new file
Browse files- lib/utils/split_dataset.py +29 -0
lib/utils/split_dataset.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import random
|
| 3 |
+
import shutil
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
def split(path, mask_path, lane_path):
|
| 7 |
+
os.mkdir(path + 'train')
|
| 8 |
+
os.mkdir(path + 'val')
|
| 9 |
+
os.mkdir(mask_path + 'train')
|
| 10 |
+
os.mkdir(mask_path + 'val')
|
| 11 |
+
os.mkdir(lane_path + 'train')
|
| 12 |
+
os.mkdir(lane_path + 'val')
|
| 13 |
+
val_index = random.sample(range(660), 200)
|
| 14 |
+
for i in range(660):
|
| 15 |
+
if i in val_index:
|
| 16 |
+
shutil.move(path+'{}.png'.format(i), path + 'val')
|
| 17 |
+
shutil.move(mask_path+'{}.png'.format(i), mask_path + 'val')
|
| 18 |
+
shutil.move(lane_path+'{}.png'.format(i), lane_path + 'val')
|
| 19 |
+
else:
|
| 20 |
+
shutil.move(path+'{}.png'.format(i), path + 'train')
|
| 21 |
+
shutil.move(mask_path+'{}.png'.format(i), mask_path + 'train')
|
| 22 |
+
shutil.move(lane_path+'{}.png'.format(i), lane_path + 'train')
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
if __name__ == '__main__':
|
| 26 |
+
path = "/home/wqm/bdd/data_hust/"
|
| 27 |
+
mask_path = "/home/wqm/bdd/hust_area/"
|
| 28 |
+
lane_path = "/home/wqm/bdd/hust_lane/"
|
| 29 |
+
split(path, mask_path, lane_path)
|