Skip to content
This repository was archived by the owner on Mar 3, 2024. It is now read-only.

Latest commit

 

History

History
39 lines (26 loc) · 818 Bytes

File metadata and controls

39 lines (26 loc) · 818 Bytes

Torch SAME Padding

License

The padding calculation used for converting TensorFlow convolution or pooling layers with SAME padding to PyTorch.

Install

pip install git+https://github.com/CyberZHG/torch-same-pad.git

Usage

import torch
import torch.nn.functional as F

from torch_same_pad import get_pad, pad


x = torch.Tensor()


# Use `get_pad` to calculate the padding
torch_pad = get_pad(size=20,
                    kernel_size=3,
                    stride=1,
                    dilation=1)
torch_output = F.pad(x, pad=torch_pad)


# Use `pad` to do the padding directly
torch_padded = pad(x,
                   size=(224, 224),
                   kernel_size=3,
                   stride=1,
                   dilation=1)