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

Python gen_nn_ops._max_pool_grad函数代码示例

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

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



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

示例1: _CompareMaxPoolingBk

 def _CompareMaxPoolingBk(self, input_shape, output_shape, ksize, strides,
                          padding):
   # Generate numbers in a narrow range, so that there are many duplicates
   # in the input.
   tensor_input = np.random.random_integers(0, 3,
                                            input_shape).astype(np.float32)
   tensor_output = np.random.rand(*output_shape).astype(np.float32)
   with self.test_session(use_gpu=True):
     t = tf.constant(tensor_input, shape=input_shape)
     _, argmax_op = tf.nn.max_pool_with_argmax(t, ksize, strides, padding)
     argmax = argmax_op.eval()
     grad_in = tf.constant(tensor_output, shape=output_shape)
     out_op = gen_nn_ops._max_pool_grad_with_argmax(t, grad_in, argmax,
                                                    ksize, strides, padding)
     gpu_val = out_op.eval()
     self.assertShapeEqual(gpu_val, out_op)
   with self.test_session(use_gpu=False):
     t = tf.constant(tensor_input, shape=input_shape)
     out_op = tf.nn.max_pool(t, ksize, strides, padding)
     orig_out = out_op.eval()
     grad_in = tf.constant(tensor_output, shape=output_shape)
     out_op = gen_nn_ops._max_pool_grad(t, orig_out, grad_in, ksize,
                                        strides, padding)
     cpu_val = out_op.eval()
     self.assertShapeEqual(cpu_val, out_op)
   self.assertAllClose(cpu_val, gpu_val, rtol=1e-5, atol=1e-5)
开发者ID:13683116633,项目名称:tensorflow,代码行数:26,代码来源:pooling_ops_test.py


示例2: _CompareMaxPoolingBk

 def _CompareMaxPoolingBk(self, input_shape, output_shape, ksize, strides,
                          padding):
   for dtype in np.float32, np.float16:
     # Generate numbers in a narrow range, so that there are many duplicates
     # in the input.
     tensor_input = np.random.random_integers(0, 3, input_shape).astype(dtype)
     tensor_output = np.random.rand(*output_shape).astype(dtype)
     with self.test_session(use_gpu=True):
       t = constant_op.constant(tensor_input, shape=input_shape)
       _, argmax_op = nn_ops.max_pool_with_argmax(t, ksize, strides, padding)
       argmax = argmax_op.eval()
       grad_in = constant_op.constant(tensor_output, shape=output_shape)
       out_op = gen_nn_ops._max_pool_grad_with_argmax(t, grad_in, argmax,
                                                      ksize, strides, padding)
       gpu_val = out_op.eval()
       self.assertShapeEqual(gpu_val, out_op)
     with self.test_session(use_gpu=False):
       t = constant_op.constant(tensor_input, shape=input_shape)
       out_op = nn_ops.max_pool(t, ksize, strides, padding)
       orig_out = out_op.eval()
       grad_in = constant_op.constant(tensor_output, shape=output_shape)
       out_op = gen_nn_ops._max_pool_grad(t, orig_out, grad_in, ksize, strides,
                                          padding)
       cpu_val = out_op.eval()
       self.assertShapeEqual(cpu_val, out_op)
     if dtype == np.float16:
       # The CPU version accumulates its gradient on fp16, so it's less
       # accurate than the GPU version that does the accumulation on fp32
       self.assertAllClose(cpu_val, gpu_val, rtol=0.01, atol=0.01)
     else:
       self.assertAllClose(cpu_val, gpu_val)
开发者ID:AliMiraftab,项目名称:tensorflow,代码行数:31,代码来源:pooling_ops_test.py


示例3: _MaxPoolGrad

def _MaxPoolGrad(op, grad):
  return gen_nn_ops._max_pool_grad(op.inputs[0], op.outputs[0], grad,
                                   op.get_attr("ksize"),
                                   op.get_attr("strides"),
                                   padding=op.get_attr("padding"),
                                   data_format=op.get_attr("data_format")
                                  )
开发者ID:2er0,项目名称:tensorflow,代码行数:7,代码来源:nn_grad.py


示例4: _MaxPoolWithArgmaxGrad

def _MaxPoolWithArgmaxGrad(op, grad, arg):
  return gen_nn_ops._max_pool_grad(op.inputs[0],
                                   op.outputs[0],
                                   grad,
                                   op.get_attr("ksize"),
                                   op.get_attr("strides"),
                                   padding=op.get_attr("padding"),
                                   data_format='NHWC')
开发者ID:mwalton,项目名称:deep-q-learning,代码行数:8,代码来源:cae.py


示例5: _MaxPoolGradGrad

def _MaxPoolGradGrad(op, grad):
    ksize = op.get_attr("ksize")
    strides = op.get_attr("strides")
    padding = op.get_attr("padding")
    data_format = op.get_attr("data_format")
    grads = []
    for i in op.inputs:
        igrad = gen_nn_ops._max_pool_grad(i, op.outputs[0], grad, ksize, strides,
                                          padding=padding,data_format=data_format)
        grads.append(igrad)

    return grads
开发者ID:mwalton,项目名称:deep-q-learning,代码行数:12,代码来源:tensorflow_backend.py


示例6: _MaxPoolGradGradGrad

def _MaxPoolGradGradGrad(op, grad):
  return (array_ops.zeros(shape=array_ops.shape(op.inputs[0]),
                          dtype=op.inputs[0].dtype),
          array_ops.zeros(shape=array_ops.shape(op.inputs[1]),
                          dtype=op.inputs[1].dtype),
          gen_nn_ops._max_pool_grad(op.inputs[0],
                                    op.inputs[1],
                                    grad,
                                    op.get_attr("ksize"),
                                    op.get_attr("strides"),
                                    padding=op.get_attr("padding"),
                                    data_format=op.get_attr("data_format")))
开发者ID:LugarkPirog,项目名称:tensorflow,代码行数:12,代码来源:nn_grad.py


示例7: _MaxPoolGrad

    def _MaxPoolGrad(self, orig_input, orig_output, grad, window_rows, window_cols, row_stride, col_stride, padding):
        """Max Pooling Gradient.

    Args:
      orig_input: A float Tensor. The original input tensor.
      orig_output: A float Tensor. The original output tensor.
      grad: A float Tensor.
        The 4D (batch x rows x cols x depth) output backprop.
      window_rows: integer. Kernel size along rows dimension.
      window_cols: integer. Kernel size along cols dimension.
      row_stride: integer. Stride along rows dimension
      col_stride: integer. Stride along cols dimension
      padding: PoolingOpDef.Padding.  Padding type.

    Returns:
      A Tensor.
    """
        return gen_nn_ops._max_pool_grad(
            orig_input, orig_output, grad, [1, window_rows, window_cols, 1], [1, row_stride, col_stride, 1], padding
        )
开发者ID:peace195,项目名称:tensorflow,代码行数:20,代码来源:pooling_ops_test.py


示例8: testDirectUseOverlapping

 def testDirectUseOverlapping(self):
   for num_batches in [1, 3]:
     for row_window_size in [2, 5]:
       for col_window_size in [2, 4]:
         num_rows = (row_window_size - 1) * 5 + 1
         num_cols = (col_window_size - 1) * 7 + 1
         for num_channels in [1, 2]:
           input_shape = (num_batches, num_rows, num_cols, num_channels)
           with self.test_session() as _:
             input_tensor = constant_op.constant(
                 self._GenerateUniqueRandomInputTensor(input_shape))
             window_size = [1, row_window_size, col_window_size, 1]
             stride_size = [1, row_window_size - 1, col_window_size - 1, 1]
             padding = "VALID"
             output_tensor = nn_ops.max_pool(input_tensor, window_size,
                                             stride_size, padding)
             output_data = output_tensor.eval()
             output_backprop = self._PRNG.randint(100, size=output_data.shape)
             input_backprop_tensor = gen_nn_ops._max_pool_grad(input_tensor,
                                                               output_tensor,
                                                               output_backprop,
                                                               window_size,
                                                               stride_size,
                                                               padding)
             input_backprop = input_backprop_tensor.eval()
             row_seq = list(range(0, num_rows, row_window_size - 1))
             col_seq = list(range(0, num_cols, col_window_size - 1))
             row_seq[-1] += 1
             col_seq[-1] += 1
             fmp_input_backprop_tensor = gen_nn_ops._fractional_max_pool_grad(
                 input_tensor,
                 output_tensor,
                 output_backprop,
                 row_seq,
                 col_seq,
                 overlapping=True)
             fmp_input_backprop = fmp_input_backprop_tensor.eval()
             self.assertShapeEqual(input_backprop, fmp_input_backprop_tensor)
             self.assertAllClose(input_backprop, fmp_input_backprop)
开发者ID:1000sprites,项目名称:tensorflow,代码行数:39,代码来源:fractional_max_pool_op_test.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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