forked from estebandito22/NYUDeepLearningProject
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample.py
More file actions
32 lines (25 loc) · 861 Bytes
/
Copy pathsample.py
File metadata and controls
32 lines (25 loc) · 861 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
27
28
29
30
31
32
import os
import json
import argparse
import numpy as np
def sample(datajson, size=100):
size = int(size)
cur_dir = os.getcwd()
inputfolder = "input"
datafolder = "MSRVTT"
jsonpath = os.path.join(cur_dir, inputfolder, datafolder, datajson)
data = json.load(open(jsonpath, "r"))
assert(len(data["data"]) >= size)
np.random.shuffle(data["data"])
data_sample = json.dumps({"data": data["data"][:size]})
sample = open(jsonpath+".sample", "w")
sample.write(data_sample)
if __name__=="__main__":
ap = argparse.ArgumentParser()
ap.add_argument("-d", "--datajson", required=True,
help="name of data.json file")
ap.add_argument("-n", "--size", default=100, required=False,
help="sample size")
args = vars(ap.parse_args())
print(args['datajson'])
sample(args['datajson'], args['size'])