class_docstr: 2D Convolutions like TensorFlow's 'SAME' mode, with the given input image size.
  The padding mudule is calculated in construction function, then used in forward.
class_docstr_tok: ["2D","Convolutions","like","TensorFlow","'s","'SAME","'","mode",",","with","the","given","input","image","size",".","The","padding","mudule","is","calculated","in","construction","function",",","then","used","in","forward","."]
code: def __init__(
      self,
      in_channels,
      out_channels,
      kernel_size,
      stride=1,
      image_size=None,
      **kwargs,
  ):
      super().__init__(
          in_channels, out_channels, kernel_size, stride, **kwargs
      )
      self.stride = (
          self.stride if len(self.stride) == 2 else [self.stride[0]] * 2
      )
  
      # Calculate padding based on image size and save it
      assert image_size is not None
      ih, iw = (
          (image_size, image_size)
          if isinstance(image_size, int)
          else image_size
      )
      kh, kw = self.weight.size()[-2:]
      sh, sw = self.stride
      oh, ow = math.ceil(ih / sh), math.ceil(iw / sw)
      pad_h = max(
          (oh - 1) * self.stride[0]
          + (kh - 1) * self.dilation[0]
          + 1
          - ih,
          0,
      )
      pad_w = max(
          (ow - 1) * self.stride[1]
          + (kw - 1) * self.dilation[1]
          + 1
          - iw,
          0,
      )
      if pad_h > 0 or pad_w > 0:
          self.static_padding = nn.ZeroPad2d(
              (
                  pad_w // 2,
                  pad_w - pad_w // 2,
                  pad_h // 2,
                  pad_h - pad_h // 2,
              )
          )
      else:
          self.static_padding = nn.Identity()
  
imports: import re
  import math
  import collections
  from functools import partial
  import torch
  from torch import nn
  from torch.nn import functional
  from torch.utils import model_zoo
label_desc: Use image node_id 1 to create a new Conv2dStaticSamePadding object from inherited base classes: nn with example: obj = Conv2dStaticSamePadding(in_channels, out_channels, kernel_size, stride, image_size)