-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgenerateBlurred.py
70 lines (54 loc) · 1.8 KB
/
generateBlurred.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
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/python
'''Script to generate random images with grayscale values in the range 0-1 and blur them with sigma which has been input by the user'''
import argparse
import matplotlib
matplotlib.use('Agg')
import numpy as np
from matplotlib import pyplot as plt
from pylab import *
from scipy.ndimage.filters import gaussian_filter
import cPickle
parser = argparse.ArgumentParser()
parser.add_argument('sigma', type=float, help = 'the blur value to blur the image with')
parser.add_argument('trainsize', type=int, help = 'training set size')
parser.add_argument('testsize', type=int, help='test set size')
parser.add_argument('filename', type=str, help ='the filename where you want to store the pickled files')
args = parser.parse_args()
sigma = args.sigma
filename = args.filename
trainsize = args.trainsize
testsize = args.testsize
maininps = []
maintargs = []
print "Sigma used:", sigma
for i in range(trainsize+testsize):
img = np.random.ranf((28,28))
out = gaussian_filter(img, sigma)
out = out.reshape((28*28,))
img = img.reshape((28*28,))
maininps.append(img)
maintargs.append(out)
seq = [i for i in range(len(maininps))]
np.random.shuffle(seq)
train_x = []; train_y = []
test_x = []; test_y = []
print
for i in seq[:trainsize]:
train_x.append(maininps[i])
train_y.append(maintargs[i])
for i in seq[trainsize:]:
test_x.append(maininps[i])
test_y.append(maintargs[i])
train_x,train_y,test_x,test_y = map(lambda x: np.array(x), [train_x, train_y, test_x, test_y])
train = (train_x,train_y)
test = (test_x, test_y)
print "Training and test sets created. Saving to disk"
trainfile = filename + '_train.pkl'
f = open(trainfile, 'wb')
cPickle.dump(train, f)
f.close()
testfile = filename + '_test.pkl'
f = open(testfile, 'wb')
cPickle.dump(test, f)
f.close()
print "Saved successfully to disk..."