Upload domainnet/train_validation_split.py with huggingface_hub
Browse files
domainnet/train_validation_split.py
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import random
|
2 |
+
domains = ["clipart", "infograph", "painting", "quickdraw", "real", "sketch"]
|
3 |
+
|
4 |
+
random.seed(42)
|
5 |
+
for domain in domains:
|
6 |
+
with open(domain + '_train.txt', 'r') as f:
|
7 |
+
domain_data = f.readlines()
|
8 |
+
random.shuffle(domain_data)
|
9 |
+
valid_data = domain_data[0:int(len(domain_data)*0.2)]
|
10 |
+
train_data = domain_data[int(len(domain_data)*0.2):]
|
11 |
+
|
12 |
+
with open(domain + '_train_fold.txt', 'w') as f:
|
13 |
+
f.write("".join(train_data))
|
14 |
+
with open(domain + '_valid_fold.txt', 'w') as f:
|
15 |
+
f.write("".join(valid_data))
|