zoukankan      html  css  js  c++  java
  • tesnorflow Conv2DTranspose

    tensorflow/python/layers/convolutional.py   
      # Infer the dynamic output shape:
        out_height = utils.deconv_output_length(height,
                                                kernel_h,
                                                self.padding,
                                                stride_h)
        out_width = utils.deconv_output_length(width,
                                               kernel_w,
                                               self.padding,
                                               stride_w)
        if self.data_format == 'channels_first':
          output_shape = (batch_size, self.filters, out_height, out_width)
          strides = (1, 1, stride_h, stride_w)
        else:
          output_shape = (batch_size, out_height, out_width, self.filters)
          strides = (1, stride_h, stride_w, 1)
    
        output_shape_tensor = array_ops.stack(output_shape)
        outputs = nn.conv2d_transpose(
            inputs,
            self.kernel,
            output_shape_tensor,
            strides,
            padding=self.padding.upper(),
            data_format=utils.convert_data_format(self.data_format, ndim=4))
    
    /tensorflow/python/layers/utils.py
    def deconv_output_length(input_length, filter_size, padding, stride):
      """Determines output length of a transposed convolution given input length.
      Arguments:
          input_length: integer.
          filter_size: integer.
          padding: one of "same", "valid", "full".
          stride: integer.
      Returns:
          The output length (integer).
      """
      if input_length is None:
        return None
      input_length *= stride
      if padding == 'valid':
        input_length += max(filter_size - stride, 0)
      elif padding == 'full':
        input_length -= (stride + filter_size - 2)
      return input_length
    

      

    注意 deconv中的kernel 是需要rotate 180度 才直接相乘的,而conv中不用旋转直接相乘。

  • 相关阅读:
    Java MyBatis 插入数据库返回主键
    FISCO-BCOS平台共识
    分布式一致性协议介绍(Paxos、Raft)
    分布式问题分析
    分布式基础知识
    比特币编译(Ubuntu 16.04)
    比特币源代码分析(1)
    c++中的多线程
    剑指offer中数据结构与算法部分学习
    基础的语法知识汇总
  • 原文地址:https://www.cnblogs.com/mlj318/p/7131075.html
Copyright © 2011-2022 走看看