当前位置: 首页>>代码示例>>Python>>正文


Python tensorflow.histogram_fixed_width方法代码示例

本文整理汇总了Python中tensorflow.histogram_fixed_width方法的典型用法代码示例。如果您正苦于以下问题:Python tensorflow.histogram_fixed_width方法的具体用法?Python tensorflow.histogram_fixed_width怎么用?Python tensorflow.histogram_fixed_width使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tensorflow的用法示例。


在下文中一共展示了tensorflow.histogram_fixed_width方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_two_updates_on_constant_input

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import histogram_fixed_width [as 别名]
def test_two_updates_on_constant_input(self):
    # Bins will be:
    #   (-inf, 1), [1, 2), [2, 3), [3, 4), [4, inf)
    value_range = [0.0, 5.0]
    values_1 = [-1.0, 0.0, 1.5, 2.0, 5.0, 15]
    values_2 = [1.5, 4.5, 4.5, 4.5, 0.0, 0.0]
    expected_bin_counts_1 = [2, 1, 1, 0, 2]
    expected_bin_counts_2 = [2, 1, 0, 0, 3]
    with self.test_session():
      values = tf.placeholder(tf.float32, shape=[6])
      hist = tf.histogram_fixed_width(values, value_range, nbins=5)

      # The values in hist should depend on the current feed and nothing else.
      self.assertAllClose(expected_bin_counts_1,
                          hist.eval(feed_dict={values: values_1}))
      self.assertAllClose(expected_bin_counts_2,
                          hist.eval(feed_dict={values: values_2}))
      self.assertAllClose(expected_bin_counts_1,
                          hist.eval(feed_dict={values: values_1}))
      self.assertAllClose(expected_bin_counts_1,
                          hist.eval(feed_dict={values: values_1})) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:23,代码来源:histogram_ops_test.py

示例2: test_two_updates_on_scalar_input

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import histogram_fixed_width [as 别名]
def test_two_updates_on_scalar_input(self):
    # Bins will be:
    #   (-inf, 1), [1, 2), [2, 3), [3, 4), [4, inf)
    value_range = [0.0, 5.0]
    values_1 = 1.5
    values_2 = 2.5
    expected_bin_counts_1 = [0, 1, 0, 0, 0]
    expected_bin_counts_2 = [0, 0, 1, 0, 0]
    with self.test_session():
      values = tf.placeholder(tf.float32, shape=[])
      hist = tf.histogram_fixed_width(values, value_range, nbins=5)

      # The values in hist should depend on the current feed and nothing else.
      self.assertAllClose(expected_bin_counts_2,
                          hist.eval(feed_dict={values: values_2}))
      self.assertAllClose(expected_bin_counts_1,
                          hist.eval(feed_dict={values: values_1}))
      self.assertAllClose(expected_bin_counts_1,
                          hist.eval(feed_dict={values: values_1}))
      self.assertAllClose(expected_bin_counts_2,
                          hist.eval(feed_dict={values: values_2})) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:23,代码来源:histogram_ops_test.py

示例3: contrast

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import histogram_fixed_width [as 别名]
def contrast(image, factor):
  """Equivalent of PIL Contrast."""
  degenerate = tf.image.rgb_to_grayscale(image)
  # Cast before calling tf.histogram.
  degenerate = tf.cast(degenerate, tf.int32)

  # Compute the grayscale histogram, then compute the mean pixel value,
  # and create a constant image size of that value.  Use that as the
  # blending degenerate target of the original image.
  hist = tf.histogram_fixed_width(degenerate, [0, 255], nbins=256)
  mean = tf.reduce_sum(tf.cast(hist, tf.float32)) / 256.0
  degenerate = tf.ones_like(degenerate, dtype=tf.float32) * mean
  degenerate = tf.clip_by_value(degenerate, 0.0, 255.0)
  degenerate = tf.image.grayscale_to_rgb(tf.cast(degenerate, tf.uint8))
  return blend(degenerate, image, factor) 
开发者ID:artyompal,项目名称:tpu_models,代码行数:17,代码来源:autoaugment_utils.py

示例4: equalize

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import histogram_fixed_width [as 别名]
def equalize(image):
  """Implements Equalize function from PIL using TF ops."""
  def scale_channel(im, c):
    """Scale the data in the channel to implement equalize."""
    im = tf.cast(im[:, :, c], tf.int32)
    # Compute the histogram of the image channel.
    histo = tf.histogram_fixed_width(im, [0, 255], nbins=256)

    # For the purposes of computing the step, filter out the nonzeros.
    nonzero = tf.where(tf.not_equal(histo, 0))
    nonzero_histo = tf.reshape(tf.gather(histo, nonzero), [-1])
    step = (tf.reduce_sum(nonzero_histo) - nonzero_histo[-1]) // 255

    def build_lut(histo, step):
      # Compute the cumulative sum, shifting by step // 2
      # and then normalization by step.
      lut = (tf.cumsum(histo) + (step // 2)) // step
      # Shift lut, prepending with 0.
      lut = tf.concat([[0], lut[:-1]], 0)
      # Clip the counts to be in range.  This is done
      # in the C code for image.point.
      return tf.clip_by_value(lut, 0, 255)

    # If step is zero, return the original image.  Otherwise, build
    # lut from the full histogram and step and then index from it.
    result = tf.cond(tf.equal(step, 0),
                     lambda: im,
                     lambda: tf.gather(build_lut(histo, step), im))

    return tf.cast(result, tf.uint8)

  # Assumes RGB for now.  Scales each channel independently
  # and then stacks the result.
  s1 = scale_channel(image, 0)
  s2 = scale_channel(image, 1)
  s3 = scale_channel(image, 2)
  image = tf.stack([s1, s2, s3], 2)
  return image 
开发者ID:artyompal,项目名称:tpu_models,代码行数:40,代码来源:autoaugment_utils.py

示例5: test_empty_input_gives_all_zero_counts

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import histogram_fixed_width [as 别名]
def test_empty_input_gives_all_zero_counts(self):
    # Bins will be:
    #   (-inf, 1), [1, 2), [2, 3), [3, 4), [4, inf)
    value_range = [0.0, 5.0]
    values = []
    expected_bin_counts = [0, 0, 0, 0, 0]
    with self.test_session():
      hist = tf.histogram_fixed_width(values, value_range, nbins=5)

      # Hist should start "fresh" with every eval.
      self.assertAllClose(expected_bin_counts, hist.eval())
      self.assertAllClose(expected_bin_counts, hist.eval()) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:14,代码来源:histogram_ops_test.py

示例6: test_one_update_on_constant_input

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import histogram_fixed_width [as 别名]
def test_one_update_on_constant_input(self):
    # Bins will be:
    #   (-inf, 1), [1, 2), [2, 3), [3, 4), [4, inf)
    value_range = [0.0, 5.0]
    values = [-1.0, 0.0, 1.5, 2.0, 5.0, 15]
    expected_bin_counts = [2, 1, 1, 0, 2]
    with self.test_session():
      hist = tf.histogram_fixed_width(values, value_range, nbins=5)

      # Hist should start "fresh" with every eval.
      self.assertAllClose(expected_bin_counts, hist.eval())
      self.assertAllClose(expected_bin_counts, hist.eval()) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:14,代码来源:histogram_ops_test.py

示例7: test_one_update_on_constant_2d_input

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import histogram_fixed_width [as 别名]
def test_one_update_on_constant_2d_input(self):
    # Bins will be:
    #   (-inf, 1), [1, 2), [2, 3), [3, 4), [4, inf)
    value_range = [0.0, 5.0]
    values = [[-1.0, 0.0, 1.5], [2.0, 5.0, 15]]
    expected_bin_counts = [2, 1, 1, 0, 2]
    with self.test_session():
      hist = tf.histogram_fixed_width(values, value_range, nbins=5)

      # Hist should start "fresh" with every eval.
      self.assertAllClose(expected_bin_counts, hist.eval())
      self.assertAllClose(expected_bin_counts, hist.eval()) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:14,代码来源:histogram_ops_test.py

示例8: contrast

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import histogram_fixed_width [as 别名]
def contrast(image: tf.Tensor, factor: float) -> tf.Tensor:
  """Equivalent of PIL Contrast."""
  degenerate = tf.image.rgb_to_grayscale(image)
  # Cast before calling tf.histogram.
  degenerate = tf.cast(degenerate, tf.int32)

  # Compute the grayscale histogram, then compute the mean pixel value,
  # and create a constant image size of that value.  Use that as the
  # blending degenerate target of the original image.
  hist = tf.histogram_fixed_width(degenerate, [0, 255], nbins=256)
  mean = tf.reduce_sum(tf.cast(hist, tf.float32)) / 256.0
  degenerate = tf.ones_like(degenerate, dtype=tf.float32) * mean
  degenerate = tf.clip_by_value(degenerate, 0.0, 255.0)
  degenerate = tf.image.grayscale_to_rgb(tf.cast(degenerate, tf.uint8))
  return blend(degenerate, image, factor) 
开发者ID:tensorflow,项目名称:models,代码行数:17,代码来源:augment.py

示例9: equalize

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import histogram_fixed_width [as 别名]
def equalize(image: tf.Tensor) -> tf.Tensor:
  """Implements Equalize function from PIL using TF ops."""
  def scale_channel(im, c):
    """Scale the data in the channel to implement equalize."""
    im = tf.cast(im[:, :, c], tf.int32)
    # Compute the histogram of the image channel.
    histo = tf.histogram_fixed_width(im, [0, 255], nbins=256)

    # For the purposes of computing the step, filter out the nonzeros.
    nonzero = tf.where(tf.not_equal(histo, 0))
    nonzero_histo = tf.reshape(tf.gather(histo, nonzero), [-1])
    step = (tf.reduce_sum(nonzero_histo) - nonzero_histo[-1]) // 255

    def build_lut(histo, step):
      # Compute the cumulative sum, shifting by step // 2
      # and then normalization by step.
      lut = (tf.cumsum(histo) + (step // 2)) // step
      # Shift lut, prepending with 0.
      lut = tf.concat([[0], lut[:-1]], 0)
      # Clip the counts to be in range.  This is done
      # in the C code for image.point.
      return tf.clip_by_value(lut, 0, 255)

    # If step is zero, return the original image.  Otherwise, build
    # lut from the full histogram and step and then index from it.
    result = tf.cond(tf.equal(step, 0),
                     lambda: im,
                     lambda: tf.gather(build_lut(histo, step), im))

    return tf.cast(result, tf.uint8)

  # Assumes RGB for now.  Scales each channel independently
  # and then stacks the result.
  s1 = scale_channel(image, 0)
  s2 = scale_channel(image, 1)
  s3 = scale_channel(image, 2)
  image = tf.stack([s1, s2, s3], 2)
  return image 
开发者ID:tensorflow,项目名称:models,代码行数:40,代码来源:augment.py

示例10: histogram

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import histogram_fixed_width [as 别名]
def histogram(x, nbins):
  """Returns the Tensor containing the nbins values of the normalized histogram of x""" 
  h = tf.histogram_fixed_width(x, value_range = [-1.0,1.0], 
                               nbins = nbins, dtype = tf.float32)
  return(h) 
开发者ID:NicoRahm,项目名称:CGvsPhoto,代码行数:7,代码来源:model.py

示例11: histogram

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import histogram_fixed_width [as 别名]
def histogram(tensor, value_range=[0.0, 1.0], nbins=100):
    """Return histogram of tensor"""
    h, w, c = tensor.shape
    hist = tf.histogram_fixed_width(tensor, value_range, nbins=nbins)
    hist = tf.divide(hist, h * w * c)
    return hist 
开发者ID:TheFoundryVisionmongers,项目名称:nuke-ML-server,代码行数:8,代码来源:train_regression.py

示例12: equalize_image

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import histogram_fixed_width [as 别名]
def equalize_image(image: TensorLike, data_format: str = "channels_last") -> tf.Tensor:
    """Implements Equalize function from PIL using TF ops."""

    @tf.function
    def scale_channel(image, channel):
        """Scale the data in the channel to implement equalize."""
        image_dtype = image.dtype

        if data_format == "channels_last":
            image = tf.cast(image[:, :, channel], tf.int32)
        elif data_format == "channels_first":
            image = tf.cast(image[channel], tf.int32)
        else:
            raise ValueError(
                "data_format can either be channels_last or channels_first"
            )
        # Compute the histogram of the image channel.
        histo = tf.histogram_fixed_width(image, [0, 255], nbins=256)

        # For the purposes of computing the step, filter out the nonzeros.
        nonzero = tf.where(tf.not_equal(histo, 0))
        nonzero_histo = tf.reshape(tf.gather(histo, nonzero), [-1])
        step = (tf.reduce_sum(nonzero_histo) - nonzero_histo[-1]) // 255

        def build_lut(histo, step):
            # Compute the cumulative sum, shifting by step // 2
            # and then normalization by step.
            lut = (tf.cumsum(histo) + (step // 2)) // step
            # Shift lut, prepending with 0.
            lut = tf.concat([[0], lut[:-1]], 0)
            # Clip the counts to be in range.  This is done
            # in the C code for image.point.
            return tf.clip_by_value(lut, 0, 255)

        # If step is zero, return the original image.  Otherwise, build
        # lut from the full histogram and step and then index from it.

        if step == 0:
            result = image
        else:
            result = tf.gather(build_lut(histo, step), image)

        return tf.cast(result, image_dtype)

    idx = 2 if data_format == "channels_last" else 0
    image = tf.stack([scale_channel(image, c) for c in range(image.shape[idx])], idx)

    return image 
开发者ID:tensorflow,项目名称:addons,代码行数:50,代码来源:color_ops.py


注:本文中的tensorflow.histogram_fixed_width方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。