-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathload_data_nhq_si.py
99 lines (85 loc) · 3.71 KB
/
load_data_nhq_si.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/env python
# written by Dr. Haiqiang Niu, Fall 2016
import numpy
class DataSet(object):
def __init__(self, images, labels, fake_data=False):
if fake_data:
self._num_examples = 10000
else:
assert images.shape[0] == labels.shape[0], (
"images.shape: %s labels.shape: %s" % (images.shape,
labels.shape))
self._num_examples = images.shape[0]
# Convert shape from [num examples, rows, columns, depth]
# to [num examples, rows*columns] (assuming depth == 1)
#assert images.shape[3] == 1
#images = images.reshape(images.shape[0],
# images.shape[1] * images.shape[2])
# Convert from [0, 255] -> [0.0, 1.0].
# images = images.astype(numpy.float32)
#images = numpy.multiply(images, 1.0 / 255.0)
self._images = images
self._labels = labels
self._epochs_completed = 0
self._index_in_epoch = 0
@property
def images(self):
return self._images
@property
def labels(self):
return self._labels
@property
def num_examples(self):
return self._num_examples
@property
def epochs_completed(self):
return self._epochs_completed
def next_batch(self, batch_size, fake_data=False):
"""Return the next `batch_size` examples from this data set."""
if fake_data:
fake_image = [1.0 for _ in xrange(34)]
fake_label = 0
return [fake_image for _ in xrange(batch_size)], [
fake_label for _ in xrange(batch_size)]
start = self._index_in_epoch
self._index_in_epoch += batch_size
if self._index_in_epoch > self._num_examples:
# Finished epoch
self._epochs_completed += 1
# Shuffle the data
#numpy.random.seed(42)
perm = numpy.arange(self._num_examples)
numpy.random.shuffle(perm)
self._images = self._images[perm]
self._labels = self._labels[perm]
# Start next epoch
start = 0
self._index_in_epoch = batch_size
assert batch_size <= self._num_examples
end = self._index_in_epoch
#print(start,end)
return self._images[start:end], self._labels[start:end]
def read_data_sets(train_dir, FileName,fake_data=False):
class DataSets(object):
pass
data_sets = DataSets()
if fake_data:
data_sets.train = DataSet([], [], fake_data=True)
data_sets.validation = DataSet([], [], fake_data=True)
data_sets.test = DataSet([], [], fake_data=True)
return data_sets
train_images = numpy.loadtxt(train_dir + '/train_input/'+ FileName)
train_labels = numpy.loadtxt(train_dir + '/train_label/'+FileName)
test_images = numpy.loadtxt(train_dir + '/test_input/'+FileName)
test_labels = numpy.loadtxt(train_dir + '/test_label/'+FileName)
# train_images = numpy.loadtxt(train_dir + '/Noise09_traindata_x_450Hz.txt')
# train_labels = numpy.loadtxt(train_dir + '/Noise09_traindata_y_450Hz.txt')
# test_images = numpy.loadtxt(train_dir + '/Noise09_testdata_x_450Hz.txt')
# test_labels = numpy.loadtxt(train_dir + '/Noise09_testdata_y_450Hz.txt')
if train_labels.ndim == 1:
train_labels = numpy.reshape(train_labels,(train_labels.size,1))
test_labels = numpy.reshape(test_labels,(test_labels.size,1))
print(train_images.shape,train_labels.shape,test_images.shape,test_labels.shape)
data_sets.train = DataSet(train_images, train_labels)
data_sets.test = DataSet(test_images, test_labels)
return data_sets