MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / __init__

Method __init__

neural_network/input_data.py:125–182  ·  view source on GitHub ↗

Construct a _DataSet. one_hot arg is used only if fake_data is true. `dtype` can be either `uint8` to leave the input as `[0, 255]`, or `float32` to rescale into `[0, 1]`. Seed arg provides for convenient deterministic testing. Args: images: The images

(
        self,
        images,
        labels,
        fake_data=False,
        one_hot=False,
        dtype=dtypes.float32,
        reshape=True,
        seed=None,
    )

Source from the content-addressed store, hash-verified

123 " from tensorflow/models.",
124 )
125 def __init__(
126 self,
127 images,
128 labels,
129 fake_data=False,
130 one_hot=False,
131 dtype=dtypes.float32,
132 reshape=True,
133 seed=None,
134 ):
135 """Construct a _DataSet.
136
137 one_hot arg is used only if fake_data is true. `dtype` can be either
138 `uint8` to leave the input as `[0, 255]`, or `float32` to rescale into
139 `[0, 1]`. Seed arg provides for convenient deterministic testing.
140
141 Args:
142 images: The images
143 labels: The labels
144 fake_data: Ignore inages and labels, use fake data.
145 one_hot: Bool, return the labels as one hot vectors (if True) or ints (if
146 False).
147 dtype: Output image dtype. One of [uint8, float32]. `uint8` output has
148 range [0,255]. float32 output has range [0,1].
149 reshape: Bool. If True returned images are returned flattened to vectors.
150 seed: The random seed to use.
151 """
152 seed1, seed2 = random_seed.get_seed(seed)
153 # If op level seed is not set, use whatever graph level seed is returned
154 self._rng = np.random.default_rng(seed1 if seed is None else seed2)
155 dtype = dtypes.as_dtype(dtype).base_dtype
156 if dtype not in (dtypes.uint8, dtypes.float32):
157 msg = f"Invalid image dtype {dtype!r}, expected uint8 or float32"
158 raise TypeError(msg)
159 if fake_data:
160 self._num_examples = 10000
161 self.one_hot = one_hot
162 else:
163 assert images.shape[0] == labels.shape[0], (
164 f"images.shape: {images.shape} labels.shape: {labels.shape}"
165 )
166 self._num_examples = images.shape[0]
167
168 # Convert shape from [num examples, rows, columns, depth]
169 # to [num examples, rows*columns] (assuming depth == 1)
170 if reshape:
171 assert images.shape[3] == 1
172 images = images.reshape(
173 images.shape[0], images.shape[1] * images.shape[2]
174 )
175 if dtype == dtypes.float32:
176 # Convert from [0, 255] -> [0.0, 1.0].
177 images = images.astype(np.float32)
178 images = np.multiply(images, 1.0 / 255.0)
179 self._images = images
180 self._labels = labels
181 self._epochs_completed = 0
182 self._index_in_epoch = 0

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected