Skip to content
This repository has been archived by the owner on Mar 3, 2024. It is now read-only.
/ torch-same-pad Public archive

Paddings used for converting TensorFlow conv/pool layers to PyTorch.

License

Notifications You must be signed in to change notification settings

CyberZHG/torch-same-pad

Repository files navigation

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)

About

Paddings used for converting TensorFlow conv/pool layers to PyTorch.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published