Exemple #1
0
 def compute_erosion2d(image_tensor, kernel_tensor):
     return nn_ops.erosion2d(image_tensor,
                             kernel_tensor,
                             strides=strides,
                             rates=rates,
                             padding=padding,
                             name="erosion2d")
Exemple #2
0
    def _ConstructAndTestGradient(self, image_shape, kernel_shape, strides,
                                  rates, padding, use_gpu):
        """Verifies the gradients of the erosion function.

    Args:
      image_shape: Input shape, [batch, in_height, in_width, channels].
      kernel_shape: Filter shape, [filter_height, filter_width, channels].
      strides: Output strides, specified as [stride_height, stride_width].
      rates: Atrous rates, specified as [rate_height, rate_width].
      padding: Padding type.
      use_gpu: Whether we are running on GPU.
    """
        assert image_shape[3] == kernel_shape[2]

        np.random.seed(1)  # Make it reproducible.
        image = np.random.random_sample(image_shape).astype(np.float32)
        kernel = np.random.random_sample(kernel_shape).astype(np.float32)
        image_init = np.random.random_sample(image_shape).astype(np.float32)
        kernel_init = np.random.random_sample(kernel_shape).astype(np.float32)

        strides = [1] + strides + [1]
        rates = [1] + rates + [1]

        with self.test_session(use_gpu=use_gpu):
            image_tensor = constant_op.constant(image,
                                                shape=image_shape,
                                                name="input")
            kernel_tensor = constant_op.constant(kernel,
                                                 shape=kernel_shape,
                                                 name="filter")
            out_tensor = nn_ops.erosion2d(image_tensor,
                                          kernel_tensor,
                                          strides=strides,
                                          rates=rates,
                                          padding=padding,
                                          name="erosion2d")
            out_shape = out_tensor.eval().shape

            # Small delta is necessary for argmax to remain the same.
            err = gradient_checker.compute_gradient_error(
                [image_tensor, kernel_tensor], [image_shape, kernel_shape],
                out_tensor,
                out_shape, [image_init, kernel_init],
                delta=1e-3)

        print("Erosion gradient error = %f" % err)
        self.assertLess(err, 1e-4)
  def _ConstructAndTestGradient(self, image_shape, kernel_shape, strides, rates,
                                padding, use_gpu):
    """Verifies the gradients of the erosion function.

    Args:
      image_shape: Input shape, [batch, in_height, in_width, channels].
      kernel_shape: Filter shape, [filter_height, filter_width, channels].
      strides: Output strides, specified as [stride_height, stride_width].
      rates: Atrous rates, specified as [rate_height, rate_width].
      padding: Padding type.
      use_gpu: Whether we are running on GPU.
    """
    assert image_shape[3] == kernel_shape[2]

    np.random.seed(1)  # Make it reproducible.
    image = np.random.random_sample(image_shape).astype(np.float32)
    kernel = np.random.random_sample(kernel_shape).astype(np.float32)
    image_init = np.random.random_sample(image_shape).astype(np.float32)
    kernel_init = np.random.random_sample(kernel_shape).astype(np.float32)

    strides = [1] + strides + [1]
    rates = [1] + rates + [1]

    with self.cached_session(use_gpu=use_gpu):
      image_tensor = constant_op.constant(
          image, shape=image_shape, name="input")
      kernel_tensor = constant_op.constant(
          kernel, shape=kernel_shape, name="filter")
      out_tensor = nn_ops.erosion2d(
          image_tensor,
          kernel_tensor,
          strides=strides,
          rates=rates,
          padding=padding,
          name="erosion2d")
      out_shape = self.evaluate(out_tensor).shape

      # Small delta is necessary for argmax to remain the same.
      err = gradient_checker.compute_gradient_error(
          [image_tensor, kernel_tensor], [image_shape, kernel_shape],
          out_tensor,
          out_shape, [image_init, kernel_init],
          delta=1e-3)

    print("Erosion gradient error = %f" % err)
    self.assertLess(err, 1e-4)
Exemple #4
0
    def _VerifyValues(self, image, kernel, strides, rates, padding, out,
                      use_gpu):
        """Verifies the output values of the erosion function.

    Args:
      image: Input tensor with shape: [batch, in_height, in_width, channels].
      kernel: Filter tensor with shape: [filter_height, filter_width, channels].
      strides: Output strides, specified as [stride_height, stride_width].
      rates: Atrous rates, specified as [rate_height, rate_width].
      padding: Padding type.
      out: Expected output.
      use_gpu: Whether we are running on GPU.
    """
        strides = [1] + strides + [1]
        rates = [1] + rates + [1]

        with self.test_session(use_gpu=use_gpu):
            out_tensor = nn_ops.erosion2d(constant_op.constant(image),
                                          constant_op.constant(kernel),
                                          strides=strides,
                                          rates=rates,
                                          padding=padding,
                                          name="erosion2d")
            self.assertAllClose(out, out_tensor.eval())
  def _VerifyValues(self, image, kernel, strides, rates, padding, out, use_gpu):
    """Verifies the output values of the erosion function.

    Args:
      image: Input tensor with shape: [batch, in_height, in_width, channels].
      kernel: Filter tensor with shape: [filter_height, filter_width, channels].
      strides: Output strides, specified as [stride_height, stride_width].
      rates: Atrous rates, specified as [rate_height, rate_width].
      padding: Padding type.
      out: Expected output.
      use_gpu: Whether we are running on GPU.
    """
    strides = [1] + strides + [1]
    rates = [1] + rates + [1]

    with self.cached_session(use_gpu=use_gpu):
      out_tensor = nn_ops.erosion2d(
          constant_op.constant(image),
          constant_op.constant(kernel),
          strides=strides,
          rates=rates,
          padding=padding,
          name="erosion2d")
      self.assertAllClose(out, self.evaluate(out_tensor))