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

Python nn_ops.conv2d_transpose函数代码示例

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

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



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

示例1: rebuild_image

def rebuild_image():
  h_fc1 = tf.nn.relu(tf.matmul(y_ + b_fc2, W_fc2))
  h_pool2_flat = tf.matmul(h_fc1 + b_fc1, W_fc1)
  h_pool2 = tf.reshape(h_pool2_flat, [-1, 7, 7, conv2_size]) # I think that's right...
  h_conv2 = tf.image.resize_images(h_pool2,14,14, method=tf.image.ResizeMethod.NEAREST_NEIGHBOR)
  h_pool1 = nn_ops.conv2d_transpose(h_conv2 + b_conv2,W_conv2,
      [class_size,14,14,conv1_size],[1,1,1,1])
  h_conv1 = tf.image.resize_images(h_pool1 ,28,28,method=tf.image.ResizeMethod.NEAREST_NEIGHBOR)
  x_image = nn_ops.conv2d_transpose(h_conv1 + b_conv1, W_conv1, [class_size,28,28,1], [1,1,1,1])
  x_image = tf.nn.relu(x_image)
  return x_image
开发者ID:brendon-boldt,项目名称:tengen,代码行数:11,代码来源:unrestricted.py


示例2: testConv2DTransposeSame

  def testConv2DTransposeSame(self):
    with self.test_session():
      strides = [1, 2, 2, 1]

      # Input, output: [batch, height, width, depth]
      x_shape = [2, 6, 4, 3]
      y_shape = [2, 12, 8, 2]

      # Filter: [kernel_height, kernel_width, output_depth, input_depth]
      f_shape = [3, 3, 2, 3]

      x = constant_op.constant(
          1.0, shape=x_shape, name="x", dtype=dtypes.float32)
      f = constant_op.constant(
          1.0, shape=f_shape, name="filter", dtype=dtypes.float32)
      output = nn_ops.conv2d_transpose(
          x, f, y_shape, strides=strides, padding="SAME")
      value = output.eval()

      for n in xrange(x_shape[0]):
        for k in xrange(f_shape[2]):
          for w in xrange(y_shape[2]):
            for h in xrange(y_shape[1]):
              target = 3.0
              # We add a case for locations divisible by the stride.
              h_in = h % strides[1] == 0 and h > 0 and h < y_shape[1] - 1
              w_in = w % strides[2] == 0 and w > 0 and w < y_shape[2] - 1
              if h_in and w_in:
                target += 9.0
              elif h_in or w_in:
                target += 3.0
              self.assertAllClose(target, value[n, h, w, k])
开发者ID:AbhinavJain13,项目名称:tensorflow,代码行数:32,代码来源:conv2d_transpose_test.py


示例3: testConv2DTransposeSameNCHW

  def testConv2DTransposeSameNCHW(self):
    # `NCHW` data fomat is only supported for CUDA device.
    if test.is_gpu_available(cuda_only=True):
      with self.test_session(use_gpu=True):
        strides = [1, 1, 2, 2]

        # Input, output: [batch, depth, height, width]
        x_shape = [2, 3, 6, 4]
        y_shape = [2, 2, 12, 8]

        # Filter: [kernel_height, kernel_width, output_depth, input_depth]
        f_shape = [3, 3, 2, 3]

        x = constant_op.constant(
            1.0, shape=x_shape, name="x", dtype=dtypes.float32)
        f = constant_op.constant(
            1.0, shape=f_shape, name="filter", dtype=dtypes.float32)

        output = nn_ops.conv2d_transpose(
            x, f, y_shape, strides=strides, padding="SAME", data_format="NCHW")

        value = output.eval()
        for n in xrange(x_shape[0]):
          for k in xrange(f_shape[2]):
            for w in xrange(y_shape[3]):
              for h in xrange(y_shape[2]):
                target = 3.0
                # We add a case for locations divisible by the stride.
                h_in = h % strides[2] == 0 and h > 0 and h < y_shape[2] - 1
                w_in = w % strides[3] == 0 and w > 0 and w < y_shape[3] - 1
                if h_in and w_in:
                  target += 9.0
                elif h_in or w_in:
                  target += 3.0
                self.assertAllClose(target, value[n, k, h, w])
开发者ID:AbhinavJain13,项目名称:tensorflow,代码行数:35,代码来源:conv2d_transpose_test.py


示例4: testConv2DTransposeSingleStrideNCHW

  def testConv2DTransposeSingleStrideNCHW(self):
    # `NCHW` data format is only supported for CUDA device.
    if test.is_gpu_available(cuda_only=True):
      with self.session(use_gpu=True):
        strides = [1, 1, 1, 1]

        # Input, output: [batch, depth, height, width, depth]
        x_shape = [2, 3, 6, 4]
        y_shape = [2, 2, 6, 4]

        # Filter: [kernel_height, kernel_width, output_depth, input_depth]
        f_shape = [3, 3, 2, 3]

        x = constant_op.constant(
            1.0, shape=x_shape, name="x", dtype=dtypes.float32)
        f = constant_op.constant(
            1.0, shape=f_shape, name="filter", dtype=dtypes.float32)

        output = nn_ops.conv2d_transpose(
            x, f, y_shape, strides=strides, padding="SAME", data_format="NCHW")

        value = self.evaluate(output)
        for n in xrange(x_shape[0]):
          for k in xrange(f_shape[2]):
            for w in xrange(y_shape[3]):
              for h in xrange(y_shape[2]):
                target = 4 * 3.0
                h_in = h > 0 and h < y_shape[2] - 1
                w_in = w > 0 and w < y_shape[3] - 1
                if h_in and w_in:
                  target += 5 * 3.0
                elif h_in or w_in:
                  target += 2 * 3.0
                self.assertAllClose(target, value[n, k, h, w])
开发者ID:Wajih-O,项目名称:tensorflow,代码行数:34,代码来源:conv2d_transpose_test.py


示例5: testAtrousConv2DTransposeForward

  def testAtrousConv2DTransposeForward(self):
    with self.session(use_gpu=True):
      # Input: [batch, height, width, input_depth]
      height = 9
      for width in [9, 10]:  # Test both odd and even width.
        x_shape = [2, height, width, 2]
        x = np.arange(np.prod(x_shape), dtype=np.float32).reshape(x_shape)

        # Filter: [kernel_height, kernel_width, input_depth, output_depth]
        for kernel_height in range(1, 4):
          for kernel_width in range(1, 4):
            f_shape = [kernel_height, kernel_width, 2, 2]
            f = np.arange(np.prod(f_shape), dtype=np.float32).reshape(f_shape)

            for rate in range(1, 4):
              f_up = _upsample_filters(f, rate)
              kernel_height_up = (kernel_height + (kernel_height - 1) *
                                  (rate - 1))
              kernel_width_up = kernel_width + (kernel_width - 1) * (rate - 1)

              for padding in ["SAME", "VALID"]:
                if padding == "SAME":
                  y_shape = [2, height, width, 2]
                else:
                  y_shape = [
                      2, height + kernel_height_up - 1,
                      width + kernel_width_up - 1, 2
                  ]

                y1 = nn_ops.atrous_conv2d_transpose(x, f, y_shape, rate,
                                                    padding)
                y2 = nn_ops.conv2d_transpose(
                    x, f_up, y_shape, strides=[1, 1, 1, 1], padding=padding)
                self.assertAllClose(
                    y1.eval(), self.evaluate(y2), rtol=1e-3, atol=1e-3)
开发者ID:adit-chandra,项目名称:tensorflow,代码行数:35,代码来源:atrous_conv2d_test.py


示例6: GetParams

 def GetParams(self):
   """Testing conversion of conv2d_transpose (AKA Conv2DBackpropInput)"""
   np.random.seed(1234)
   dtype = dtypes.float32
   input_name = "input"
   n, c, h, w = 13, 3, 7, 11
   num_filters = 8
   input_dims = [n, c, h, w]
   output_name = "output"
   g = ops.Graph()
   with g.as_default():
     inp = array_ops.placeholder(
         dtype=dtype, shape=[None] + input_dims[1:], name=input_name)
     with g.device("/GPU:0"):
       weights_shape = [2, 2, num_filters, c]
       weights = constant_op.constant(
           np.random.randn(*weights_shape), dtype=dtype)
       output_shape = constant_op.constant([n, num_filters, h * 2, w * 2],
                                           dtype=dtypes.int32)
       output = nn_ops.conv2d_transpose(
           inp,
           weights,
           output_shape,
           strides=[1, 1, 2, 2],
           padding="SAME",
           data_format="NCHW")
       output = array_ops.identity(output, name=output_name)
   return trt_test.TfTrtIntegrationTestParams(
       gdef=g.as_graph_def(),
       input_names=[input_name],
       input_dims=[[input_dims]],
       output_names=[output_name],
       expected_output_dims=[[[n, num_filters, h * 2, w * 2]]])
开发者ID:adit-chandra,项目名称:tensorflow,代码行数:33,代码来源:conv2d_test.py


示例7: testConv2DTransposeShapeInference

 def testConv2DTransposeShapeInference(self):
   # Test case for 8972
   initializer = random_ops.truncated_normal(
       [3, 3, 5, 1], mean=0.0, stddev=0.01, dtype=dtypes.float32)
   x = variables.Variable(random_ops.random_normal([3, 10, 5, 1]))
   f = variable_scope.get_variable("f", initializer=initializer)
   f_shape = array_ops.stack([array_ops.shape(x)[0], 10, 5, 5])
   output = nn_ops.conv2d_transpose(
       x, f, f_shape, strides=[1, 1, 1, 1], padding="SAME")
   self.assertEqual(output.get_shape().as_list(), [None, 10, 5, 5])
开发者ID:AbhinavJain13,项目名称:tensorflow,代码行数:10,代码来源:conv2d_transpose_test.py


示例8: testConv2DTransposeValidNCHW

  def testConv2DTransposeValidNCHW(self):
    # `NCHW` data fomat is only supported for CUDA device.
    if test.is_gpu_available(cuda_only=True):
      with self.test_session(use_gpu=True):
        strides = [1, 1, 2, 2]

        # Input, output: [batch, depth, height, width]
        x_shape = [2, 3, 6, 4]
        y_shape = [2, 2, 13, 9]

        # Filter: [kernel_height, kernel_width, output_depth, input_depth]
        f_shape = [3, 3, 2, 3]

        x = constant_op.constant(
            1.0, shape=x_shape, name="x", dtype=dtypes.float32)
        f = constant_op.constant(
            1.0, shape=f_shape, name="filter", dtype=dtypes.float32)
        output = nn_ops.conv2d_transpose(
            x, f, y_shape, strides=strides, padding="VALID", data_format="NCHW")

        value = output.eval()
        cache_values = np.zeros(y_shape, dtype=np.float32)
        # The amount of padding added
        pad = 1
        for n in xrange(x_shape[0]):
          for k in xrange(f_shape[2]):
            for w in xrange(pad, y_shape[3] - pad):
              for h in xrange(pad, y_shape[2] - pad):
                target = 3.0
                # We add a case for locations divisible by the stride.
                h_in = h % strides[2] == 0 and h > pad and h < y_shape[
                    2] - 1 - pad
                w_in = w % strides[3] == 0 and w > pad and w < y_shape[
                    3] - 1 - pad
                if h_in and w_in:
                  target += 9.0
                elif h_in or w_in:
                  target += 3.0
                cache_values[n, k, h, w] = target

            # copy values in the border
            cache_values[n, k, :, 0] = cache_values[n, k, :, 1]
            cache_values[n, k, :, -1] = cache_values[n, k, :, -2]
            cache_values[n, k, 0, :] = cache_values[n, k, 1, :]
            cache_values[n, k, -1, :] = cache_values[n, k, -2, :]

        self.assertAllClose(cache_values, value)
开发者ID:AbhinavJain13,项目名称:tensorflow,代码行数:47,代码来源:conv2d_transpose_test.py


示例9: testConv2DTransposeValid

  def testConv2DTransposeValid(self):
    with self.test_session():
      strides = [1, 2, 2, 1]

      # Input, output: [batch, height, width, depth]
      x_shape = [2, 6, 4, 3]
      y_shape = [2, 13, 9, 2]

      # Filter: [kernel_height, kernel_width, output_depth, input_depth]
      f_shape = [3, 3, 2, 3]

      x = constant_op.constant(
          1.0, shape=x_shape, name="x", dtype=dtypes.float32)
      f = constant_op.constant(
          1.0, shape=f_shape, name="filter", dtype=dtypes.float32)
      output = nn_ops.conv2d_transpose(
          x, f, y_shape, strides=strides, padding="VALID")
      value = output.eval()

      cache_values = np.zeros(y_shape, dtype=np.float32)

      # The amount of padding added
      pad = 1

      for n in xrange(x_shape[0]):
        for k in xrange(f_shape[2]):
          for w in xrange(pad, y_shape[2] - pad):
            for h in xrange(pad, y_shape[1] - pad):
              target = 3.0
              # We add a case for locations divisible by the stride.
              h_in = h % strides[1] == 0 and h > pad and h < y_shape[
                  1] - 1 - pad
              w_in = w % strides[2] == 0 and w > pad and w < y_shape[
                  2] - 1 - pad
              if h_in and w_in:
                target += 9.0
              elif h_in or w_in:
                target += 3.0
              cache_values[n, h, w, k] = target

          # copy values in the border
          cache_values[n, :, 0, k] = cache_values[n, :, 1, k]
          cache_values[n, :, -1, k] = cache_values[n, :, -2, k]
          cache_values[n, 0, :, k] = cache_values[n, 1, :, k]
          cache_values[n, -1, :, k] = cache_values[n, -2, :, k]

    self.assertAllClose(cache_values, value)
开发者ID:AbhinavJain13,项目名称:tensorflow,代码行数:47,代码来源:conv2d_transpose_test.py


示例10: testGradient

 def testGradient(self):
   x_shape = [2, 6, 4, 3]
   f_shape = [3, 3, 2, 3]
   y_shape = [2, 12, 8, 2]
   strides = [1, 2, 2, 1]
   np.random.seed(1)  # Make it reproducible.
   x_val = np.random.random_sample(x_shape).astype(np.float64)
   f_val = np.random.random_sample(f_shape).astype(np.float64)
   with self.test_session():
     x = constant_op.constant(x_val, name="x", dtype=dtypes.float32)
     f = constant_op.constant(f_val, name="f", dtype=dtypes.float32)
     output = nn_ops.conv2d_transpose(
         x, f, y_shape, strides=strides, padding="SAME")
     err = gradient_checker.compute_gradient_error([x, f], [x_shape, f_shape],
                                                   output, y_shape)
   print("conv2d_transpose gradient err = %g " % err)
   err_tolerance = 0.0005
   self.assertLess(err, err_tolerance)
开发者ID:AbhinavJain13,项目名称:tensorflow,代码行数:18,代码来源:conv2d_transpose_test.py


示例11: testConv2DTransposeSingleStride

  def testConv2DTransposeSingleStride(self):
    with self.test_session():
      strides = [1, 1, 1, 1]

      # Input, output: [batch, height, width, depth]
      x_shape = [2, 6, 4, 3]
      y_shape = [2, 6, 4, 2]

      # Filter: [kernel_height, kernel_width, output_depth, input_depth]
      f_shape = [3, 3, 2, 3]

      x = constant_op.constant(
          1.0, shape=x_shape, name="x", dtype=dtypes.float32)
      f = constant_op.constant(
          1.0, shape=f_shape, name="filter", dtype=dtypes.float32)
      output = nn_ops.conv2d_transpose(
          x, f, y_shape, strides=strides, padding="SAME")
      value = output.eval()

      # We count the number of cells being added at the locations in the output.
      # At the center, #cells=kernel_height * kernel_width
      # At the corners, #cells=ceil(kernel_height/2) * ceil(kernel_width/2)
      # At the borders, #cells=ceil(kernel_height/2)*kernel_width or
      #                        kernel_height * ceil(kernel_width/2)

      for n in xrange(x_shape[0]):
        for k in xrange(f_shape[2]):
          for w in xrange(y_shape[2]):
            for h in xrange(y_shape[1]):
              target = 4 * 3.0
              h_in = h > 0 and h < y_shape[1] - 1
              w_in = w > 0 and w < y_shape[2] - 1
              if h_in and w_in:
                target += 5 * 3.0
              elif h_in or w_in:
                target += 2 * 3.0
              self.assertAllClose(target, value[n, h, w, k])
开发者ID:AbhinavJain13,项目名称:tensorflow,代码行数:37,代码来源:conv2d_transpose_test.py


示例12: open

'''
  h_pool1 = nn_ops.conv2d_transpose(h_conv2 + b_conv2,W_conv2,
      [class_size,14,14,conv1_size],[1,1,1,1])
'''
index = 0
dir = "l1f/"
for t in W_conv1_t.eval():
  with open(dir+'filter'+str(index)+'.png', "wb") as file:
    t = tf.constant(t)
    #t = tf.expand_dims(tf.constant(t), 0)
    #t_n = tf.squeeze(nn_ops.conv2d_transpose(t, W_conv1, [1,5,5,1],[1,1,1,1]), [0])
    t = tf.image.resize_images(t,50,50, method=tf.image.ResizeMethod.BICUBIC)
    t = tf.constant(ops.normalize(t.eval(), 0, 255))
    file.write(tf.image.encode_png(t).eval())
  index += 1

W_conv2_t = tf.transpose(W_conv2, perm=[3,0,1,2])

index = 0
dir = "l2f/"
#for t in W_conv1_t.eval():
for t in W_conv2_t.eval():
  with open(dir+'filter'+str(index)+'.png', "wb") as file:
    t = tf.expand_dims(tf.constant(t), 0)
    t_n = tf.squeeze(nn_ops.conv2d_transpose(t, W_conv1, [1,5,5,1],[1,1,1,1]), [0])
    t_n = tf.image.resize_images(t_n,50,50, method=tf.image.ResizeMethod.BICUBIC)
    t_n = tf.constant(ops.normalize(t_n.eval(), 0, 255))
    file.write(tf.image.encode_png(t_n).eval())
  index += 1
开发者ID:brendon-boldt,项目名称:tengen,代码行数:29,代码来源:unrestricted.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python nn_ops.conv3d函数代码示例发布时间:2022-05-27
下一篇:
Python nn_ops.conv2d_backprop_input函数代码示例发布时间: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