Skip to content

Like torch grid_sample, but for binary input (B, H, W). Each bit of an uint8 input pixel corresponds to a channel.

License

Notifications You must be signed in to change notification settings

tasptz/torch-bitgridsample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

What does it do?

It works like torch grid_sample with bilinear interpolation and zero padding, but takes in uint8 datatype with shape (B, H, W), where each bit of a pixel corresponds to a channel. Encoding can be done like

sum(x[:, i] * 2**i for i in range(x.shape[1]))

Gradient flow through the input grid is supported.

Why?

To safe GPU memory. Consider the case where you want to sample small regions from large images, which only consist of binary masks. E.g. CMYK printing motives. Torch grid_sample only works for floating point types, so in case of 4 channels, memory consumption is reduced by sizeof(float) * channels = 4 * 4 = 16.

Installation

Edit the arguments BLOCKSIZE in setup.py, accordingly to your requirements. Then execute setup.py as needed, e.g.

python setup.py develop

About

Like torch grid_sample, but for binary input (B, H, W). Each bit of an uint8 input pixel corresponds to a channel.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published