MCPcopy Create free account
hub / github.com/lazyprogrammer/machine_learning_examples / DataSet

Class DataSet

tensorflow/input_data.py:62–117  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

60 return dense_to_one_hot(labels)
61 return labels
62class DataSet(object):
63 def __init__(self, images, labels, fake_data=False):
64 if fake_data:
65 self._num_examples = 10000
66 else:
67 assert images.shape[0] == labels.shape[0], (
68 "images.shape: %s labels.shape: %s" % (images.shape,
69 labels.shape))
70 self._num_examples = images.shape[0]
71 # Convert shape from [num examples, rows, columns, depth]
72 # to [num examples, rows*columns] (assuming depth == 1)
73 assert images.shape[3] == 1
74 images = images.reshape(images.shape[0],
75 images.shape[1] * images.shape[2])
76 # Convert from [0, 255] -> [0.0, 1.0].
77 images = images.astype(numpy.float32)
78 images = numpy.multiply(images, 1.0 / 255.0)
79 self._images = images
80 self._labels = labels
81 self._epochs_completed = 0
82 self._index_in_epoch = 0
83 @property
84 def images(self):
85 return self._images
86 @property
87 def labels(self):
88 return self._labels
89 @property
90 def num_examples(self):
91 return self._num_examples
92 @property
93 def epochs_completed(self):
94 return self._epochs_completed
95 def next_batch(self, batch_size, fake_data=False):
96 """Return the next `batch_size` examples from this data set."""
97 if fake_data:
98 fake_image = [1.0 for _ in xrange(784)]
99 fake_label = 0
100 return [fake_image for _ in xrange(batch_size)], [
101 fake_label for _ in xrange(batch_size)]
102 start = self._index_in_epoch
103 self._index_in_epoch += batch_size
104 if self._index_in_epoch > self._num_examples:
105 # Finished epoch
106 self._epochs_completed += 1
107 # Shuffle the data
108 perm = numpy.arange(self._num_examples)
109 numpy.random.shuffle(perm)
110 self._images = self._images[perm]
111 self._labels = self._labels[perm]
112 # Start next epoch
113 start = 0
114 self._index_in_epoch = batch_size
115 assert batch_size <= self._num_examples
116 end = self._index_in_epoch
117 return self._images[start:end], self._labels[start:end]
118def read_data_sets(train_dir, fake_data=False, one_hot=False):
119 class DataSets(object):

Callers 1

read_data_setsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected