• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python image_ops.resize_bilinear函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中tensorflow.python.ops.image_ops.resize_bilinear函数的典型用法代码示例。如果您正苦于以下问题:Python resize_bilinear函数的具体用法?Python resize_bilinear怎么用?Python resize_bilinear使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: preprocess_image

def preprocess_image(
    images, height=INCEPTION_DEFAULT_IMAGE_SIZE,
    width=INCEPTION_DEFAULT_IMAGE_SIZE, scope=None):
  """Prepare a batch of images for evaluation.

  This is the preprocessing portion of the graph from
  http://download.tensorflow.org/models/image/imagenet/inception-2015-12-05.tgz.

  Note that it expects Tensors in [0, 255]. This function maps pixel values to
  [-1, 1] and resizes to match the InceptionV1 network.

  Args:
    images: 3-D or 4-D Tensor of images. Values are in [0, 255].
    height: Integer. Height of resized output image.
    width: Integer. Width of resized output image.
    scope: Optional scope for name_scope.

  Returns:
    3-D or 4-D float Tensor of prepared image(s). Values are in [-1, 1].
  """
  is_single = images.shape.ndims == 3
  with ops.name_scope(scope, 'preprocess', [images, height, width]):
    if not images.dtype.is_floating:
      images = math_ops.to_float(images)
    if is_single:
      images = array_ops.expand_dims(images, axis=0)
    resized = image_ops.resize_bilinear(images, [height, width])
    resized = (resized - 128.0) / 128.0
    if is_single:
      resized = array_ops.squeeze(resized, axis=0)
    return resized
开发者ID:changchunli,项目名称:compare_gan,代码行数:31,代码来源:classifier_metrics_impl.py


示例2: testFuseResizeAndConv

  def testFuseResizeAndConv(self):
    with self.cached_session() as sess:
      inputs = [1, 4, 2, 5, 3, 6, -1, -4, -2, -5, -3, -6]
      input_op = constant_op.constant(
          np.array(inputs), shape=[1, 2, 3, 2], dtype=dtypes.float32)
      resize_op = image_ops.resize_bilinear(
          input_op, [12, 4], align_corners=False)
      weights = [1, 2, 3, 4, 0.1, 0.2, 0.3, 0.4]
      weights_op = constant_op.constant(
          np.array(weights), shape=[1, 2, 2, 2], dtype=dtypes.float32)
      nn_ops.conv2d(
          resize_op, weights_op, [1, 1, 1, 1], padding="VALID", name="output")
      original_graph_def = sess.graph_def
      original_result = sess.run(["output:0"])
    optimized_graph_def = optimize_for_inference_lib.fuse_resize_and_conv(
        original_graph_def, ["output"])

    with self.cached_session() as sess:
      _ = importer.import_graph_def(
          optimized_graph_def, input_map={}, name="optimized")
      optimized_result = sess.run(["optimized/output:0"])

    self.assertAllClose(original_result, optimized_result)

    for node in optimized_graph_def.node:
      self.assertNotEqual("Conv2D", node.op)
      self.assertNotEqual("MirrorPad", node.op)
开发者ID:Wajih-O,项目名称:tensorflow,代码行数:27,代码来源:optimize_for_inference_test.py


示例3: testGradOnUnsupportedType

  def testGradOnUnsupportedType(self):
    in_shape = [1, 4, 6, 1]
    out_shape = [1, 2, 3, 1]

    x = np.arange(0, 24).reshape(in_shape).astype(np.uint8)

    with self.test_session():
      input_tensor = constant_op.constant(x, shape=in_shape)
      resize_out = image_ops.resize_bilinear(input_tensor, out_shape[1:3])
      grad = gradients_impl.gradients(input_tensor, [resize_out])
      self.assertEqual([None], grad)
开发者ID:1000sprites,项目名称:tensorflow,代码行数:11,代码来源:image_grad_test.py


示例4: testGradFromResizeToSmallerInBothDims

  def testGradFromResizeToSmallerInBothDims(self):
    in_shape = [1, 4, 6, 1]
    out_shape = [1, 2, 3, 1]

    x = np.arange(0, 24).reshape(in_shape).astype(np.float32)

    with self.test_session():
      input_tensor = constant_op.constant(x, shape=in_shape)
      resize_out = image_ops.resize_bilinear(input_tensor, out_shape[1:3])
      err = gradient_checker.compute_gradient_error(
          input_tensor, in_shape, resize_out, out_shape, x_init_value=x)
    self.assertLess(err, 1e-3)
开发者ID:1000sprites,项目名称:tensorflow,代码行数:12,代码来源:image_grad_test.py


示例5: testShapeIsCorrectAfterOp

  def testShapeIsCorrectAfterOp(self):
    in_shape = [1, 2, 2, 1]
    out_shape = [1, 4, 6, 1]

    x = np.arange(0, 4).reshape(in_shape).astype(np.float32)

    with self.test_session() as sess:
      input_tensor = constant_op.constant(x, shape=in_shape)
      resize_out = image_ops.resize_bilinear(input_tensor, out_shape[1:3])
      self.assertEqual(out_shape, list(resize_out.get_shape()))

      resize_out = sess.run(resize_out)
      self.assertEqual(out_shape, list(resize_out.shape))
开发者ID:1000sprites,项目名称:tensorflow,代码行数:13,代码来源:image_grad_test.py


示例6: testCompareGpuVsCpu

  def testCompareGpuVsCpu(self):
    in_shape = [2, 4, 6, 3]
    out_shape = [2, 8, 16, 3]

    size = np.prod(in_shape)
    x = 1.0 / size * np.arange(0, size).reshape(in_shape).astype(np.float32)
    for align_corners in [True, False]:
      grad = {}
      for use_gpu in [False, True]:
        with self.test_session(use_gpu=use_gpu):
          input_tensor = constant_op.constant(x, shape=in_shape)
          resized_tensor = image_ops.resize_bilinear(
              input_tensor, out_shape[1:3], align_corners=align_corners)
          grad[use_gpu] = gradient_checker.compute_gradient(
              input_tensor, in_shape, resized_tensor, out_shape, x_init_value=x)

      self.assertAllClose(grad[False], grad[True], rtol=1e-4, atol=1e-4)
开发者ID:1000sprites,项目名称:tensorflow,代码行数:17,代码来源:image_grad_test.py


示例7: testTypes

  def testTypes(self):
    in_shape = [1, 4, 6, 1]
    out_shape = [1, 2, 3, 1]
    x = np.arange(0, 24).reshape(in_shape)

    with self.cached_session() as sess:
      for dtype in [np.float16, np.float32, np.float64]:
        input_tensor = constant_op.constant(x.astype(dtype), shape=in_shape)
        resize_out = image_ops.resize_bilinear(input_tensor, out_shape[1:3])
        grad = sess.run(gradients_impl.gradients(resize_out, input_tensor))[0]
        self.assertAllEqual(in_shape, grad.shape)
        # Not using gradient_checker.compute_gradient as I didn't work out
        # the changes required to compensate for the lower precision of
        # float16 when computing the numeric jacobian.
        # Instead, we just test the theoretical jacobian.
        self.assertAllEqual([[[[1.], [0.], [1.], [0.], [1.], [0.]], [[0.], [
            0.
        ], [0.], [0.], [0.], [0.]], [[1.], [0.], [1.], [0.], [1.], [0.]],
                              [[0.], [0.], [0.], [0.], [0.], [0.]]]], grad)
开发者ID:Wajih-O,项目名称:tensorflow,代码行数:19,代码来源:image_grad_test.py


示例8: testCompareGpuVsCpu

  def testCompareGpuVsCpu(self):
    in_shape = [2, 4, 6, 3]
    out_shape = [2, 8, 16, 3]

    size = np.prod(in_shape)
    x = 1.0 / size * np.arange(0, size).reshape(in_shape).astype(np.float32)

    # Align corners will be deprecated for tf2.0 and the false version is not
    # supported by XLA.
    align_corner_options = [True
                           ] if test_util.is_xla_enabled() else [True, False]
    for align_corners in align_corner_options:
      grad = {}
      for use_gpu in [False, True]:
        with self.cached_session(use_gpu=use_gpu):
          input_tensor = constant_op.constant(x, shape=in_shape)
          resized_tensor = image_ops.resize_bilinear(
              input_tensor, out_shape[1:3], align_corners=align_corners)
          grad[use_gpu] = gradient_checker.compute_gradient(
              input_tensor, in_shape, resized_tensor, out_shape, x_init_value=x)

      self.assertAllClose(grad[False], grad[True], rtol=1e-4, atol=1e-4)
开发者ID:aritratony,项目名称:tensorflow,代码行数:22,代码来源:image_grad_test.py


示例9: preprocess_image

def preprocess_image(
    image, height=INCEPTION_V3_DEFAULT_IMG_SIZE,
    width=INCEPTION_V3_DEFAULT_IMG_SIZE, central_fraction=0.875, scope=None):
  """Prepare one image for evaluation.

  If height and width are specified it would output an image with that size by
  applying resize_bilinear.

  If central_fraction is specified it would crop the central fraction of the
  input image.

  Args:
    image: 3-D Tensor of image. If dtype is tf.float32 then the range should be
      [0, 1], otherwise it would converted to tf.float32 assuming that the range
      is [0, MAX], where MAX is largest positive representable number for
      int(8/16/32) data type (see `tf.image.convert_image_dtype` for details).
    height: integer
    width: integer
    central_fraction: Optional Float, fraction of the image to crop.
    scope: Optional scope for name_scope.
  Returns:
    3-D float Tensor of prepared image.
  """
  with ops.name_scope(scope, 'eval_image', [image, height, width]):
    if image.dtype != dtypes.float32:
      image = image_ops.convert_image_dtype(image, dtype=dtypes.float32)
    # Crop the central region of the image with an area containing 87.5% of
    # the original image.
    image = image_ops.central_crop(image, central_fraction=central_fraction)

    # Resize the image to the specified height and width.
    image = array_ops.expand_dims(image, 0)
    image = image_ops.resize_bilinear(image, [height, width],
                                      align_corners=False)
    image = array_ops.squeeze(image, [0])
    image = (image - 0.5) * 2.0
    return image
开发者ID:Crazyonxh,项目名称:tensorflow,代码行数:37,代码来源:classifier_metrics_impl.py


示例10: _resize_image

def _resize_image(image, height, width):
  image = array_ops.expand_dims(image, 0)
  image = image_ops.resize_bilinear(image, [height, width])
  return array_ops.squeeze(image, [0])
开发者ID:1000sprites,项目名称:tensorflow,代码行数:4,代码来源:dataset_data_provider_test.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python image_ops.resize_images函数代码示例发布时间:2022-05-27
下一篇:
Python image_ops.hsv_to_rgb函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap