This repository has been archived by the owner on Jul 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.py
55 lines (44 loc) · 1.91 KB
/
script.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
import os
import numpy as np
import pickle
def save_to_npy(path_from, path_to):
images = []
labels = []
for line in open(path_from, 'r').readlines():
nums = [float(x) for x in line.split()]
images.append(nums[:-1])
labels.append(int(nums[-1]))
images = np.asarray(images)
labels = np.asarray(labels)
c = [images, labels]
pickle_file = open(path_to, 'wb')
pickle.dump(c, pickle_file)
def generate_rotated():
dir_name = "/home/x/Downloads/mnist_data"
train_file = os.path.join(dir_name, 'mnist_all_rotation_normalized_float_train_valid.amat')
test_file = os.path.join(dir_name, 'mnist_all_rotation_normalized_float_test.amat')
save_to_npy(train_file, 'rotation_train.pkl')
save_to_npy(test_file, 'rotation_test.pkl')
def generate_rndback():
dir_name = "/home/x/Downloads/mnist_data"
train_file = os.path.join(dir_name, 'mnist_background_random_train.amat')
test_file = os.path.join(dir_name, 'mnist_background_random_test.amat')
save_to_npy(train_file, 'rndback_train.pkl')
save_to_npy(test_file, 'rndback_test.pkl')
def genarate_imgback():
dir_name = "/home/x/Downloads/mnist_data"
train_file = os.path.join(dir_name, 'mnist_background_images_train.amat')
test_file = os.path.join(dir_name, 'mnist_background_images_test.amat')
save_to_npy(train_file, 'imgback_train.pkl')
save_to_npy(test_file, 'imgback_test.pkl')
def generate_imgback_rot():
dir_name = "/home/x/Downloads/mnist_data"
train_file = os.path.join(dir_name, 'mnist_all_background_images_rotation_normalized_train_valid.amat')
test_file = os.path.join(dir_name, 'mnist_all_background_images_rotation_normalized_test.amat')
save_to_npy(train_file, 'imgback_rot_train.pkl')
save_to_npy(test_file, 'imgback_rot_test.pkl')
if __name__ == '__main__':
# generate_rotated()
# genarate_imgback()
# generate_rndback()
generate_imgback_rot()