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.

Source Distribution

masked-convolution-0.3.1.tar.gz (6.4 kB view details)

Uploaded Source

File details

Details for the file masked-convolution-0.3.1.tar.gz.

File metadata

  • Download URL: masked-convolution-0.3.1.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0.post20200714 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

File hashes

Hashes for masked-convolution-0.3.1.tar.gz
Algorithm Hash digest
SHA256 fa84c37a313faaee4cc1e877a48340b83c1b025785ef742f3aed27800ce8d6ea
MD5 d5c9617b599aa751eceff52a0f2f39be
BLAKE2b-256 2850ae5b3819c66fb2f40c0818370ae0e5304f9e48db1c6e5f8b1ba9bbe8b1d4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page