Python tensorflow.python.framework.dtypes.uint8() Examples
The following are 30
code examples of tensorflow.python.framework.dtypes.uint8().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
tensorflow.python.framework.dtypes
, or try the search function
.
Example #1
Source File: dataset.py From classification-of-encrypted-traffic with MIT License | 6 votes |
def extract_labels(dataframe, one_hot=False, num_classes=10): """Extract the labels into a 1D uint8 numpy array [index]. Args: dataframe: A pandas dataframe object. one_hot: Does one hot encoding for the result. num_classes: Number of classes for the one hot encoding. Returns: labels: a 1D uint8 numpy array. """ print('Extracting labels', ) labels = dataframe['label'].values labels = _label_encoder.fit_transform(labels) if one_hot: return dense_to_one_hot(labels, num_classes) return labels
Example #2
Source File: image_ops_test.py From deep_image_model with Apache License 2.0 | 6 votes |
def testResizeDownArea(self): img_shape = [1, 6, 6, 1] data = [128, 64, 32, 16, 8, 4, 4, 8, 16, 32, 64, 128, 128, 64, 32, 16, 8, 4, 5, 10, 15, 20, 25, 30, 30, 25, 20, 15, 10, 5, 5, 10, 15, 20, 25, 30] img_np = np.array(data, dtype=np.uint8).reshape(img_shape) target_height = 4 target_width = 4 expected_data = [73, 33, 23, 39, 73, 33, 23, 39, 14, 16, 19, 21, 14, 16, 19, 21] with self.test_session(use_gpu=True): image = constant_op.constant(img_np, shape=img_shape) y = image_ops.resize_images(image, [target_height, target_width], image_ops.ResizeMethod.AREA) expected = np.array(expected_data).reshape( [1, target_height, target_width, 1]) resized = y.eval() self.assertAllClose(resized, expected, atol=1)
Example #3
Source File: tfexample_decoder_test.py From auto-alt-text-lambda-api with MIT License | 6 votes |
def GenerateImage(self, image_format, image_shape): """Generates an image and an example containing the encoded image. Args: image_format: the encoding format of the image. image_shape: the shape of the image to generate. Returns: image: the generated image. example: a TF-example with a feature key 'image/encoded' set to the serialized image and a feature key 'image/format' set to the image encoding format ['jpeg', 'JPEG', 'png', 'PNG', 'raw']. """ num_pixels = image_shape[0] * image_shape[1] * image_shape[2] image = np.linspace( 0, num_pixels - 1, num=num_pixels).reshape(image_shape).astype(np.uint8) tf_encoded = self._Encoder(image, image_format) example = example_pb2.Example(features=feature_pb2.Features(feature={ 'image/encoded': self._EncodedBytesFeature(tf_encoded), 'image/format': self._StringFeature(image_format) })) return image, example.SerializeToString()
Example #4
Source File: image_ops_test.py From deep_image_model with Apache License 2.0 | 6 votes |
def _RGBToGrayscale(self, images): is_batch = True if len(images.shape) == 3: is_batch = False images = np.expand_dims(images, axis=0) out_shape = images.shape[0:3] + (1,) out = np.zeros(shape=out_shape, dtype=np.uint8) for batch in xrange(images.shape[0]): for y in xrange(images.shape[1]): for x in xrange(images.shape[2]): red = images[batch, y, x, 0] green = images[batch, y, x, 1] blue = images[batch, y, x, 2] gray = 0.2989 * red + 0.5870 * green + 0.1140 * blue out[batch, y, x, 0] = int(gray) if not is_batch: out = np.squeeze(out, axis=0) return out
Example #5
Source File: image_ops_test.py From deep_image_model with Apache License 2.0 | 6 votes |
def testConvertBetweenInt16AndInt8(self): with self.test_session(use_gpu=True): # uint8, uint16 self._convert([0, 255 * 256], dtypes.uint16, dtypes.uint8, [0, 255]) self._convert([0, 255], dtypes.uint8, dtypes.uint16, [0, 255 * 256]) # int8, uint16 self._convert([0, 127 * 2 * 256], dtypes.uint16, dtypes.int8, [0, 127]) self._convert([0, 127], dtypes.int8, dtypes.uint16, [0, 127 * 2 * 256]) # int16, uint16 self._convert([0, 255 * 256], dtypes.uint16, dtypes.int16, [0, 255 * 128]) self._convert([0, 255 * 128], dtypes.int16, dtypes.uint16, [0, 255 * 256])
Example #6
Source File: image_ops_test.py From deep_image_model with Apache License 2.0 | 6 votes |
def testBasicGrayscaleToRGB(self): # 4-D input with batch dimension. x_np = np.array([[1, 2]], dtype=np.uint8).reshape([1, 1, 2, 1]) y_np = np.array([[1, 1, 1], [2, 2, 2]], dtype=np.uint8).reshape([1, 1, 2, 3]) with self.test_session(use_gpu=True): x_tf = constant_op.constant(x_np, shape=x_np.shape) y = image_ops.grayscale_to_rgb(x_tf) y_tf = y.eval() self.assertAllEqual(y_tf, y_np) # 3-D input with no batch dimension. x_np = np.array([[1, 2]], dtype=np.uint8).reshape([1, 2, 1]) y_np = np.array([[1, 1, 1], [2, 2, 2]], dtype=np.uint8).reshape([1, 2, 3]) with self.test_session(use_gpu=True): x_tf = constant_op.constant(x_np, shape=x_np.shape) y = image_ops.grayscale_to_rgb(x_tf) y_tf = y.eval() self.assertAllEqual(y_tf, y_np)
Example #7
Source File: entropy_models.py From pcc_geo_cnn with MIT License | 6 votes |
def visualize(self): """Multi-channel visualization of densities as images. Creates and returns an image summary visualizing the current probabilty density estimates. The image contains one row for each channel. Within each row, the pixel intensities are proportional to probability values, and each row is centered on the median of the corresponding distribution. Returns: The created image summary. """ with ops.name_scope(self._name_scope()): image = self._pmf image *= 255 / math_ops.reduce_max(image, axis=1, keepdims=True) image = math_ops.cast(image + .5, dtypes.uint8) image = image[None, :, :, None] return summary.image("pmf", image, max_outputs=1)
Example #8
Source File: image_ops_test.py From deep_image_model with Apache License 2.0 | 6 votes |
def test_adjust_gamma_less_one(self): """Verifying the output with expected results for gamma correction with gamma equal to half""" with self.test_session(): x_np = np.arange(0, 255, 4, np.uint8).reshape(8,8) y = image_ops.adjust_gamma(x_np, gamma=0.5) y_tf = np.trunc(y.eval()) y_np = np.array([[ 0, 31, 45, 55, 63, 71, 78, 84], [ 90, 95, 100, 105, 110, 115, 119, 123], [127, 131, 135, 139, 142, 146, 149, 153], [156, 159, 162, 165, 168, 171, 174, 177], [180, 183, 186, 188, 191, 194, 196, 199], [201, 204, 206, 209, 211, 214, 216, 218], [221, 223, 225, 228, 230, 232, 234, 236], [238, 241, 243, 245, 247, 249, 251, 253]], dtype=np.float32) self.assertAllClose(y_tf, y_np, 1e-6)
Example #9
Source File: image_ops_test.py From deep_image_model with Apache License 2.0 | 6 votes |
def test_adjust_gamma_greater_one(self): """Verifying the output with expected results for gamma correction with gamma equal to two""" with self.test_session(): x_np = np.arange(0, 255, 4, np.uint8).reshape(8,8) y = image_ops.adjust_gamma(x_np, gamma=2) y_tf = np.trunc(y.eval()) y_np = np.array([[ 0, 0, 0, 0, 1, 1, 2, 3], [ 4, 5, 6, 7, 9, 10, 12, 14], [ 16, 18, 20, 22, 25, 27, 30, 33], [ 36, 39, 42, 45, 49, 52, 56, 60], [ 64, 68, 72, 76, 81, 85, 90, 95], [100, 105, 110, 116, 121, 127, 132, 138], [144, 150, 156, 163, 169, 176, 182, 189], [196, 203, 211, 218, 225, 233, 241, 249]], dtype=np.float32) self.assertAllClose(y_tf, y_np, 1e-6)
Example #10
Source File: cifar10.py From memoryGAN with MIT License | 5 votes |
def extract_labels(f, one_hot=False, num_classes=10): """Extract the labels into a 1D uint8 numpy array [index]. Args: f: A file object that can be passed into a gzip reader. one_hot: Does one hot encoding for the result. num_classes: Number of classes for the one hot encoding. Returns: labels: a 1D uint8 numpy array. Raises: ValueError: If the bystream doesn't start with 2049. """ print('Extracting', f.name) with gzip.GzipFile(fileobj=f) as bytestream: magic = _read32(bytestream) if magic != 2049: raise ValueError('Invalid magic number %d in MNIST label file: %s' % (magic, f.name)) num_items = _read32(bytestream) buf = bytestream.read(num_items) labels = numpy.frombuffer(buf, dtype=numpy.uint8) if one_hot: return dense_to_one_hot(labels, num_classes) return labels
Example #11
Source File: dataset.py From tanda with MIT License | 5 votes |
def extract_images(f): """Extract the images into a 4D uint8 numpy array [index, y, x, depth]. Args: f: A file object that can be passed into a gzip reader. Returns: data: A 4D uint8 numpy array [index, y, x, depth]. Raises: ValueError: If the bytestream does not start with 2051. """ print('Extracting', f.name) with gzip.GzipFile(fileobj=f) as bytestream: magic = _read32(bytestream) if magic != 2051: raise ValueError('Invalid magic number %d in MNIST image file: %s' % (magic, f.name)) num_images = _read32(bytestream) rows = _read32(bytestream) cols = _read32(bytestream) buf = bytestream.read(rows * cols * num_images) data = numpy.frombuffer(buf, dtype=numpy.uint8) data = data.reshape(num_images, rows, cols, 1) return data
Example #12
Source File: dataset.py From tanda with MIT License | 5 votes |
def extract_labels(f, one_hot=False, num_classes=10): """Extract the labels into a 1D uint8 numpy array [index]. Args: f: A file object that can be passed into a gzip reader. one_hot: Does one hot encoding for the result. num_classes: Number of classes for the one hot encoding. Returns: labels: a 1D uint8 numpy array. Raises: ValueError: If the bystream doesn't start with 2049. """ print('Extracting', f.name) with gzip.GzipFile(fileobj=f) as bytestream: magic = _read32(bytestream) if magic != 2049: raise ValueError('Invalid magic number %d in MNIST label file: %s' % (magic, f.name)) num_items = _read32(bytestream) buf = bytestream.read(num_items) labels = numpy.frombuffer(buf, dtype=numpy.uint8) if one_hot: return dense_to_one_hot(labels, num_classes) return labels
Example #13
Source File: dataset.py From tanda with MIT License | 5 votes |
def __init__(self, images, labels, fake_data=False, one_hot=False, dtype=dtypes.float32, reshape=True): """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]`. """ dtype = dtypes.as_dtype(dtype).base_dtype if dtype not in (dtypes.uint8, dtypes.float32): raise TypeError('Invalid image dtype %r, expected uint8 or float32' % dtype) if fake_data: self._num_examples = 10000 self.one_hot = one_hot 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) if reshape: assert images.shape[3] == 1 images = images.reshape(images.shape[0], images.shape[1] * images.shape[2]) if dtype == dtypes.float32: # 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
Example #14
Source File: cifar10.py From memoryGAN with MIT License | 5 votes |
def extract_images(f): """Extract the images into a 4D uint8 numpy array [index, y, x, depth]. Args: f: A file object that can be passed into a gzip reader. Returns: data: A 4D uint8 numpy array [index, y, x, depth]. Raises: ValueError: If the bytestream does not start with 2051. """ print('Extracting', f.name) with gzip.GzipFile(fileobj=f) as bytestream: magic = _read32(bytestream) if magic != 2051: raise ValueError('Invalid magic number %d in MNIST image file: %s' % (magic, f.name)) num_images = _read32(bytestream) rows = _read32(bytestream) cols = _read32(bytestream) buf = bytestream.read(rows * cols * num_images) data = numpy.frombuffer(buf, dtype=numpy.uint8) data = data.reshape(num_images, rows, cols, 1) return data
Example #15
Source File: datasets.py From memoryGAN with MIT License | 5 votes |
def __init__(self, images, labels, fake_data=False, one_hot=False, dtype=dtypes.float32, reshape=True): """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]`. """ dtype = dtypes.as_dtype(dtype).base_dtype if dtype not in (dtypes.uint8, dtypes.float32): raise TypeError('Invalid image dtype %r, expected uint8 or float32' % dtype) if fake_data: self._num_examples = 10000 self.one_hot = one_hot else: assert images.shape[0] == labels.shape[0], ( 'images.shape: %s labels.shape: %s' % (images.shape, labels.shape)) self._num_examples = images.shape[0] if dtype == dtypes.float32: images = images.astype(numpy.float32) self._images = images self._labels = labels self._epochs_completed = 0 self._index_in_epoch = 0
Example #16
Source File: image_ops_test.py From deep_image_model with Apache License 2.0 | 5 votes |
def testNoConvert(self): # Make sure converting to the same data type creates only an identity op with self.test_session(use_gpu=True): image = constant_op.constant([1], dtype=dtypes.uint8) image_ops.convert_image_dtype(image, dtypes.uint8) y = image_ops.convert_image_dtype(image, dtypes.uint8) self.assertEquals(y.op.type, 'Identity') self.assertEquals(y.op.inputs[0], image)
Example #17
Source File: image_ops_test.py From deep_image_model with Apache License 2.0 | 5 votes |
def testPartialShapes(self): p_unknown_rank = array_ops.placeholder(dtypes.uint8) p_unknown_dims = array_ops.placeholder(dtypes.uint8, shape=[None, None, None]) p_unknown_width = array_ops.placeholder(dtypes.uint8, shape=[64, None, 3]) p_wrong_rank = array_ops.placeholder(dtypes.uint8, shape=[None, None]) p_zero_dim = array_ops.placeholder(dtypes.uint8, shape=[64, 0, 3]) for op in [image_ops.flip_left_right, image_ops.flip_up_down, image_ops.random_flip_left_right, image_ops.random_flip_up_down, image_ops.transpose_image, image_ops.rot90]: transformed_unknown_rank = op(p_unknown_rank) self.assertEqual(3, transformed_unknown_rank.get_shape().ndims) transformed_unknown_dims = op(p_unknown_dims) self.assertEqual(3, transformed_unknown_dims.get_shape().ndims) transformed_unknown_width = op(p_unknown_width) self.assertEqual(3, transformed_unknown_width.get_shape().ndims) with self.assertRaisesRegexp(ValueError, 'must be three-dimensional'): op(p_wrong_rank) with self.assertRaisesRegexp(ValueError, 'must be > 0'): op(p_zero_dim)
Example #18
Source File: dataset.py From classification-of-encrypted-traffic with MIT License | 5 votes |
def __init__(self, payloads, labels, dtype=dtypes.float32, seed=None): """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. """ seed1, seed2 = random_seed.get_seed(seed) # If op level seed is not set, use whatever graph level seed is returned np.random.seed(seed1 if seed is None else seed2) dtype = dtypes.as_dtype(dtype).base_dtype if dtype not in (dtypes.uint8, dtypes.float32): raise TypeError('Invalid payload dtype %r, expected uint8 or float32' % dtype) assert payloads.shape[0] == labels.shape[0], ( 'payloads.shape: %s labels.shape: %s' % (payloads.shape, labels.shape)) self._num_examples = payloads.shape[0] if dtype == dtypes.float32: # Convert from [0, 255] -> [0.0, 1.0]. payloads = payloads.astype(np.float32) payloads = np.multiply(payloads, 1.0 / 255.0) self._payloads = payloads self._labels = labels self._epochs_completed = 0 self._index_in_epoch = 0
Example #19
Source File: image_ops_test.py From deep_image_model with Apache License 2.0 | 5 votes |
def testValid(self): # Read some real GIFs prefix = 'tensorflow/core/lib/gif/testdata/' filename = 'scan.gif' WIDTH = 20 HEIGHT = 40 STRIDE = 5 shape = (12, HEIGHT, WIDTH, 3) with self.test_session(use_gpu=True) as sess: gif0 = io_ops.read_file(prefix + filename) image0 = image_ops.decode_gif(gif0) gif0, image0 = sess.run([gif0, image0]) self.assertEqual(image0.shape, shape) for frame_idx, frame in enumerate(image0): gt = np.zeros(shape[1:], dtype=np.uint8) start = frame_idx * STRIDE end = (frame_idx + 1) * STRIDE print(frame_idx) if end <= WIDTH: gt[:, start:end, :] = 255 else: start -= WIDTH end -= WIDTH gt[start:end, :, :] = 255 self.assertAllClose(frame, gt)
Example #20
Source File: image_ops_test.py From deep_image_model with Apache License 2.0 | 5 votes |
def _SimpleColorRamp(): """Build a simple color ramp RGB image.""" w, h = 256, 200 i = np.arange(h)[:, None] j = np.arange(w) image = np.empty((h, w, 3), dtype=np.uint8) image[:, :, 0] = i image[:, :, 1] = j image[:, :, 2] = (i + j) >> 1 return image
Example #21
Source File: image_ops_test.py From deep_image_model with Apache License 2.0 | 5 votes |
def testSumTensor(self): img_shape = [1, 6, 4, 1] # This test is also conducted with int8, so 127 is the maximum # value that can be used. data = [127, 127, 64, 64, 127, 127, 64, 64, 64, 64, 127, 127, 64, 64, 127, 127, 50, 50, 100, 100, 50, 50, 100, 100] # Test size where width is specified as a tensor which is a sum # of two tensors. width_1 = constant_op.constant(1) width_2 = constant_op.constant(3) width = math_ops.add(width_1, width_2) height = constant_op.constant(6) img_np = np.array(data, dtype=np.uint8).reshape(img_shape) for opt in self.OPTIONS: with self.test_session() as sess: image = constant_op.constant(img_np, shape=img_shape) y = image_ops.resize_images(image, [height, width], opt) yshape = array_ops.shape(y) resized, newshape = sess.run([y, yshape]) self.assertAllEqual(img_shape, newshape) self.assertAllClose(resized, img_np, atol=1e-5)
Example #22
Source File: image_ops_test.py From deep_image_model with Apache License 2.0 | 5 votes |
def testNegativeDelta(self): x_shape = [2, 2, 3] x_data = [0, 5, 13, 54, 135, 226, 37, 8, 234, 90, 255, 1] x_np = np.array(x_data, dtype=np.uint8).reshape(x_shape) y_data = [0, 0, 3, 44, 125, 216, 27, 0, 224, 80, 245, 0] y_np = np.array(y_data, dtype=np.uint8).reshape(x_shape) self._testBrightness(x_np, y_np, delta=-10. / 255.)
Example #23
Source File: image_ops_test.py From deep_image_model with Apache License 2.0 | 5 votes |
def testPositiveDeltaUint8(self): x_shape = [2, 2, 3] x_data = [0, 5, 13, 54, 135, 226, 37, 8, 234, 90, 255, 1] x_np = np.array(x_data, dtype=np.uint8).reshape(x_shape) y_data = [10, 15, 23, 64, 145, 236, 47, 18, 244, 100, 255, 11] y_np = np.array(y_data, dtype=np.uint8).reshape(x_shape) self._testBrightness(x_np, y_np, delta=10. / 255.)
Example #24
Source File: image_ops_test.py From deep_image_model with Apache License 2.0 | 5 votes |
def testBatchDoubleContrast(self): x_shape = [2, 1, 2, 3] x_data = [0, 5, 13, 54, 135, 226, 37, 8, 234, 90, 255, 1] x_np = np.array(x_data, dtype=np.uint8).reshape(x_shape) y_data = [0, 0, 0, 81, 200, 255, 10, 0, 255, 116, 255, 0] y_np = np.array(y_data, dtype=np.uint8).reshape(x_shape) self._testContrast(x_np, y_np, contrast_factor=2.0)
Example #25
Source File: image_ops_test.py From deep_image_model with Apache License 2.0 | 5 votes |
def testHalfContrastUint8(self): x_shape = [1, 2, 2, 3] x_data = [0, 5, 13, 54, 135, 226, 37, 8, 234, 90, 255, 1] x_np = np.array(x_data, dtype=np.uint8).reshape(x_shape) y_data = [22, 52, 65, 49, 118, 172, 41, 54, 176, 67, 178, 59] y_np = np.array(y_data, dtype=np.uint8).reshape(x_shape) self._testContrast(x_np, y_np, contrast_factor=0.5)
Example #26
Source File: image_ops_test.py From deep_image_model with Apache License 2.0 | 5 votes |
def testRandomUpDown(self): x_np = np.array([0, 1], dtype=np.uint8).reshape([2, 1, 1]) num_iterations = 500 hist = [0, 0] with self.test_session(use_gpu=True): x_tf = constant_op.constant(x_np, shape=x_np.shape) y = image_ops.random_flip_up_down(x_tf) for _ in xrange(num_iterations): y_np = y.eval().flatten()[0] hist[y_np] += 1 # Ensure that each entry is observed within 4 standard deviations. four_stddev = 4.0 * np.sqrt(num_iterations / 2.0) self.assertAllClose(hist, [num_iterations / 2.0] * 2, atol=four_stddev)
Example #27
Source File: image_ops_test.py From deep_image_model with Apache License 2.0 | 5 votes |
def testRandomLeftRight(self): x_np = np.array([0, 1], dtype=np.uint8).reshape([1, 2, 1]) num_iterations = 500 hist = [0, 0] with self.test_session(use_gpu=True): x_tf = constant_op.constant(x_np, shape=x_np.shape) y = image_ops.random_flip_left_right(x_tf) for _ in xrange(num_iterations): y_np = y.eval().flatten()[0] hist[y_np] += 1 # Ensure that each entry is observed within 4 standard deviations. four_stddev = 4.0 * np.sqrt(num_iterations / 2.0) self.assertAllClose(hist, [num_iterations / 2.0] * 2, atol=four_stddev)
Example #28
Source File: image_ops_test.py From deep_image_model with Apache License 2.0 | 5 votes |
def testRot90NumpyEquivalence(self): image = np.arange(24, dtype=np.uint8).reshape([2, 4, 3]) with self.test_session(use_gpu=True): k_placeholder = array_ops.placeholder(dtypes.int32, shape=[]) y_tf = image_ops.rot90(image, k_placeholder) for k in xrange(4): y_np = np.rot90(image, k=k) self.assertAllEqual(y_np, y_tf.eval({k_placeholder: k}))
Example #29
Source File: image_ops_test.py From deep_image_model with Apache License 2.0 | 5 votes |
def testRot90GroupOrder(self): image = np.arange(24, dtype=np.uint8).reshape([2, 4, 3]) with self.test_session(use_gpu=True): rotated = image for _ in xrange(4): rotated = image_ops.rot90(rotated) self.assertAllEqual(image, rotated.eval())
Example #30
Source File: fashion.py From memoryGAN with MIT License | 5 votes |
def __init__(self, images, labels, fake_data=False, one_hot=False, dtype=dtypes.float32, reshape=True): """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]`. """ dtype = dtypes.as_dtype(dtype).base_dtype if dtype not in (dtypes.uint8, dtypes.float32): raise TypeError('Invalid image dtype %r, expected uint8 or float32' % dtype) if fake_data: self._num_examples = 10000 self.one_hot = one_hot 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) if reshape: assert images.shape[3] == 1 images = images.reshape(images.shape[0], images.shape[1] * images.shape[2]) if dtype == dtypes.float32: # 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