當前位置: 首頁>>代碼示例>>Python>>正文


Python dtypes.uint8方法代碼示例

本文整理匯總了Python中tensorflow.python.framework.dtypes.uint8方法的典型用法代碼示例。如果您正苦於以下問題:Python dtypes.uint8方法的具體用法?Python dtypes.uint8怎麽用?Python dtypes.uint8使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在tensorflow.python.framework.dtypes的用法示例。


在下文中一共展示了dtypes.uint8方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: extract_labels

# 需要導入模塊: from tensorflow.python.framework import dtypes [as 別名]
# 或者: from tensorflow.python.framework.dtypes import uint8 [as 別名]
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 
開發者ID:SalikLP,項目名稱:classification-of-encrypted-traffic,代碼行數:19,代碼來源:dataset.py

示例2: GenerateImage

# 需要導入模塊: from tensorflow.python.framework import dtypes [as 別名]
# 或者: from tensorflow.python.framework.dtypes import uint8 [as 別名]
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() 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:25,代碼來源:tfexample_decoder_test.py

示例3: _RGBToGrayscale

# 需要導入模塊: from tensorflow.python.framework import dtypes [as 別名]
# 或者: from tensorflow.python.framework.dtypes import uint8 [as 別名]
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 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:20,代碼來源:image_ops_test.py

示例4: testBasicGrayscaleToRGB

# 需要導入模塊: from tensorflow.python.framework import dtypes [as 別名]
# 或者: from tensorflow.python.framework.dtypes import uint8 [as 別名]
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) 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:23,代碼來源:image_ops_test.py

示例5: test_adjust_gamma_less_one

# 需要導入模塊: from tensorflow.python.framework import dtypes [as 別名]
# 或者: from tensorflow.python.framework.dtypes import uint8 [as 別名]
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) 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:20,代碼來源:image_ops_test.py

示例6: test_adjust_gamma_greater_one

# 需要導入模塊: from tensorflow.python.framework import dtypes [as 別名]
# 或者: from tensorflow.python.framework.dtypes import uint8 [as 別名]
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) 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:20,代碼來源:image_ops_test.py

示例7: testResizeDownArea

# 需要導入模塊: from tensorflow.python.framework import dtypes [as 別名]
# 或者: from tensorflow.python.framework.dtypes import uint8 [as 別名]
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) 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:27,代碼來源:image_ops_test.py

示例8: testConvertBetweenInt16AndInt8

# 需要導入模塊: from tensorflow.python.framework import dtypes [as 別名]
# 或者: from tensorflow.python.framework.dtypes import uint8 [as 別名]
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]) 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:19,代碼來源:image_ops_test.py

示例9: visualize

# 需要導入模塊: from tensorflow.python.framework import dtypes [as 別名]
# 或者: from tensorflow.python.framework.dtypes import uint8 [as 別名]
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) 
開發者ID:mauriceqch,項目名稱:pcc_geo_cnn,代碼行數:19,代碼來源:entropy_models.py

示例10: __init__

# 需要導入模塊: from tensorflow.python.framework import dtypes [as 別名]
# 或者: from tensorflow.python.framework.dtypes import uint8 [as 別名]
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 
開發者ID:SalikLP,項目名稱:classification-of-encrypted-traffic,代碼行數:33,代碼來源:dataset.py

示例11: extract_images

# 需要導入模塊: from tensorflow.python.framework import dtypes [as 別名]
# 或者: from tensorflow.python.framework.dtypes import uint8 [as 別名]
def extract_images(filename):
  """Extract the images into a 4D uint8 numpy array [index, y, x, depth]."""
  print('Extracting', filename)
  with open(filename, 'rb') as f, gzip.GzipFile(fileobj=f) as bytestream:
    magic = _read32(bytestream)
    if magic != 2051:
      raise ValueError('Invalid magic number %d in MNIST image file: %s' %
                       (magic, filename))
    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 
開發者ID:GoogleCloudPlatform,項目名稱:cloudml-samples,代碼行數:17,代碼來源:input_data.py

示例12: extract_labels

# 需要導入模塊: from tensorflow.python.framework import dtypes [as 別名]
# 或者: from tensorflow.python.framework.dtypes import uint8 [as 別名]
def extract_labels(filename, one_hot=False, num_classes=10):
  """Extract the labels into a 1D uint8 numpy array [index]."""
  print('Extracting', filename)
  with open(filename, 'rb') as f, gzip.GzipFile(fileobj=f) as bytestream:
    magic = _read32(bytestream)
    if magic != 2049:
      raise ValueError('Invalid magic number %d in MNIST label file: %s' %
                       (magic, filename))
    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 
開發者ID:GoogleCloudPlatform,項目名稱:cloudml-samples,代碼行數:16,代碼來源:input_data.py

示例13: __init__

# 需要導入模塊: from tensorflow.python.framework import dtypes [as 別名]
# 或者: from tensorflow.python.framework.dtypes import uint8 [as 別名]
def __init__(self,
               images,
               labels,
               start_id=0,
               fake_data=False,
               one_hot=False,
               dtype=dtypes.float32):
    """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)
      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._ids = numpy.arange(start_id, start_id + self._num_examples)
    self._images = images
    self._labels = labels
    self._epochs_completed = 0
    self._index_in_epoch = 0 
開發者ID:GoogleCloudPlatform,項目名稱:cloudml-samples,代碼行數:40,代碼來源:input_data.py

示例14: _assert_dtype

# 需要導入模塊: from tensorflow.python.framework import dtypes [as 別名]
# 或者: from tensorflow.python.framework.dtypes import uint8 [as 別名]
def _assert_dtype(images):
    """ Make sure the images are of the correct data type """
    dtype = dtypes.as_dtype(images.dtype).base_dtype
    if dtype not in (dtypes.uint8, dtypes.float32):
        raise TypeError('Invalid image dtype {0}, expected uint8 or float32'.format(dtype))

    return dtype 
開發者ID:dojoteef,項目名稱:glas,代碼行數:9,代碼來源:omniglot.py

示例15: _correct_images

# 需要導入模塊: from tensorflow.python.framework import dtypes [as 別名]
# 或者: from tensorflow.python.framework.dtypes import uint8 [as 別名]
def _correct_images(images):
    """ Convert images to be correct """
    # From the MNIST website: "Pixels are organized row-wise. Pixel values are 0 to 255. 0 means
    # background (white), 255 means foreground (black)."
    # The dataset does not transform the image such that 255 is black, so do that here.
    dtype = _assert_dtype(images)
    max_val = 255 if dtype == dtypes.uint8 else 1.0
    return max_val - images 
開發者ID:dojoteef,項目名稱:glas,代碼行數:10,代碼來源:omniglot.py


注:本文中的tensorflow.python.framework.dtypes.uint8方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。