-
Notifications
You must be signed in to change notification settings - Fork 3
/
make.py
57 lines (37 loc) · 1.47 KB
/
make.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import os
import pandas as pd
import random
path = "/mnt/c/datasets/open_structure"
data = pd.read_csv(f"{path}/train_without_outlier.csv")
os.mkdir(f"{path}/validation")
train_index = list(range(len(data)))
random.shuffle(train_index)
val_index = train_index[:int(0.2*len(train_index))]
train_index = train_index[int(0.2*len(train_index)):]
data_train = data.iloc[train_index]
data_val = data.iloc[val_index]
data_train.reset_index(drop=True, inplace=True)
data_val.reset_index(drop=True, inplace=True)
image_list = []
text_list = []
for index in range(len(data_val)):
single = data_val.iloc[index]
image_path = single["img_path"].split("/")[-1]
text = single["text"]
os.rename(f"{path}/train/{image_path}", f"{path}/validation/{image_path}")
image_list.append(f"validation/{image_path}")
text_list.append(text)
data_val = pd.DataFrame(list(zip(image_list, text_list)),
columns =['img_path', 'text'])
image_list = []
text_list = []
for index in range(len(data_train)):
single = data_train.iloc[index]
image_path = single["img_path"].split("/")[-1]
text = single["text"]
image_list.append(f"train/{image_path}")
text_list.append(text)
data_train = pd.DataFrame(list(zip(image_list, text_list)),
columns =['img_path', 'text'])
data_train.to_csv("train.tsv", sep="\t", index=False)
data_val.to_csv("validation.tsv", sep="\t", index=False)