Skip to main content

A PyTorch wrapper for masked convolutions

Project description

Masked Convolution

License

A PyTorch implementation of a thin wrapper for masked convolutions.

What are masked convolutions?

Similarly to partial convolutions, masked convolutions mask a part of the kernel, essentially ignoring data at specific locations. For an example, consider

a = [1, 2, 3, 4, 5]

assuming we have a convolution kernel

kernel = [1, 1, 1]

convolving over a would give us

a_conv = [6, 9, 12]

However, if we were to mask the convolution kernel with a mask

mask = [1, 0, 1]

masked convolving over a would return

a_masked_conv = [4, 6, 8]

One use of masked convolutions is emulating skip-grams.

Installation

First, make sure you have PyTorch installed. This was tested on Python 3.8 and PyTorch 1.7.1. Further testing is needed to determine whether it works on a different setup - chances are it does. The recommended way to install this is through PyPi by running:

pip install masked-convolution

Other than that, you can clone this repository, and in its root directory (where setup.py is located) run

pip install .

Benchmarks

Every build, automatic benchmarks are run in order to determine how much overhead the implementation brings. The ordinary convolutions are used as a baseline, while the the performance of masked convolutions is described as a percentage of throughput of their respective baselines.

Keep in mind that these benchmarks are in no way professional, they only serve to give users a general idea. Their results greatly differ, so they should be taken with a grain of salt.

  • Masked Convolution 1D: 85.29 % Convolution 1D throughput
  • Masked Convolution 2D: 85.64 % Convolution 2D throughput
  • Masked Convolution 3D: 97.79 % Convolution 3D throughput

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for masked-convolution, version 0.3.1
Filename, size File type Python version Upload date Hashes
Filename, size masked-convolution-0.3.1.tar.gz (6.4 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page