Depth-to-Space and Space-to-Depth PyTorch implementation compatible with onnx
Project description
Overview
PixelShuffle
/PixelUnshuffle
in PyTorch and depth_to_space
/space_to_depth
in TensorFlow are very similar, but they are not numerically identical unless the upsampled image contains a single channel. This can be easyly verified by hand: while the tensor dimensions match between the PyTorch and TensorFlow worlds, the output channels do not follow the same order.
However, in some deployment setups, there might be performance benefits to using the space-to-depth/depth-to-space variant. For example, at the moment of writing, Android NN API only supports depth-to-space and space-to-depth.
This repository provides a unit-tested space-to-depth/depth-to-space implementation for PyTorch, supporting conversion to SpaceToDepth/DepthToSpace ONNX ops when exporting the model as an ONNX graph for further deployment.
The provided implementation follows channels-first PyTorch standard, allowing for arbitrary number of outer dimensions, i.e. it supports tensors of [..., C, H, W]
layouts.
Installation
python3 -m pip install s2d2s
Usage
Both functional implementations and nn.Module
s are available and can be used as follows:
from s2d2s import space_to_depth, depth_to_space
y = space_to_depth(x, 2)
from s2d2s import SpaceToDepth, DepthToSpace
module = SpaceToDepth(2)
y = module(x)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file s2d2s-1.tar.gz
.
File metadata
- Download URL: s2d2s-1.tar.gz
- Upload date:
- Size: 3.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c6dc146567bd6476948f4673adb8d6fc08eae3c978542677ecc4629d9b56767 |
|
MD5 | 7c8b1513519e5f5b6fb4365eae85abe0 |
|
BLAKE2b-256 | c8b6aa4344775de942571be7273f31e1a9156435ab28ff8e7726771c1aff12b7 |
File details
Details for the file s2d2s-1-py3-none-any.whl
.
File metadata
- Download URL: s2d2s-1-py3-none-any.whl
- Upload date:
- Size: 4.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e692e0d4810e525333d81f1cea8983b8d0dbc8877aa44072bf319c6198a20eb9 |
|
MD5 | facfb6ce779ca860073af80602965a0e |
|
BLAKE2b-256 | dfb7a3737794ef4b35893b92f26e4bbba48eceec17298f72ee84bd6944d097c6 |