forked from hassan-mahmood/FCN_Segmentation_Table
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
28 lines (20 loc) · 948 Bytes
/
Copy pathexample.py
File metadata and controls
28 lines (20 loc) · 948 Bytes
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
#this file will create validation dataset from a given directory
import argparse
import os
import random
import shutil
parser=argparse.ArgumentParser()
parser.add_argument('--datadir',default='dataset/',help='Directory which contains images and labels folders')
parser.add_argument('--outputdir',default='valdataset',help='Directory where labels and images of validation dataset will be created')
if(__name__=='__main__'):
args=parser.parse_args()
datadir=args.datadir
outputdir=args.outputdir
all_images=os.listdir(os.path.join(datadir,'images'))
all_labels=os.listdir(os.path.join(datadir,'labels'))
val_data_len=int(len(all_images)*0.2)
filenames=random.sample(all_images,val_data_len)
print(filenames)
for f in filenames:
shutil.move(os.path.join(datadir,'images',f),os.path.join(outputdir,'images',f))
shutil.move(os.path.join(datadir,'labels',f),os.path.join(outputdir,'labels',f))