Implement of Perceiver, General Perception with Iterative Attention in TensorFlow
Project description
Perceiver
This Python package implements Perceiver: General Perception with Iterative Attention by Andrew Jaegle in TensorFlow. This model builds on top of Transformers such that the data only enters through the cross attention mechanism (see figure) and allow it to scale to hundreds of thousands of inputs, like ConvNets. This, in part also solves the Transformers Quadratic compute and memory bottleneck.
Yannic Kilcher's video was very helpful.
Installation
Run the following to install:
pip install perceiver
Developing perceiver
To install perceiver
, along with tools you need to develop and test, run the following in your virtualenv:
git clone https://github.com/Rishit-dagli/Perceiver.git
# or clone your own fork
cd perceiver
pip install -e .[dev]
A bit about Perceiver
The Perceiver model aims to deal with arbitrary configurations of different modalities using a single transformer-based architecture. Transformers are often flexible and make few assumptions about their inputs, but that also scale quadratically with the number of inputs in terms of both memory and computation. This model proposes a mechanism that makes it possible to deal with high-dimensional inputs, while retaining the expressivity and flexibility to deal with arbitrary input configurations.
The idea here is to introduce a small set of latent units that forms an attention bottleneck through which the inputs must pass. This avoids the quadratic scaling problem of all-to-all attention of a classical transformer. The model can be seen as performing a fully end-to-end clustering of the inputs, with the latent units as the cluster centres, leveraging a highly asymmetric crossattention layer. For spatial information the authors compensate for the lack of explicit grid structures in our model by associating Fourier feature encodings.
Usage
from perceiver import Perceiver
import tensorflow as tf
model = Perceiver(
input_channels = 3, # number of channels for each token of the input
input_axis = 2, # number of axis for input data (2 for images, 3 for video)
num_freq_bands = 6, # number of freq bands, with original value (2 * K + 1)
max_freq = 10., # maximum frequency, hyperparameter depending on how fine the data is
depth = 6, # depth of net
num_latents = 256, # number of latents
latent_dim = 512, # latent dimension
cross_heads = 1, # number of heads for cross attention. paper said 1
latent_heads = 8, # number of heads for latent self attention, 8
cross_dim_head = 64,
latent_dim_head = 64,
num_classes = 1000, # output number of classes
attn_dropout = 0.,
ff_dropout = 0.,
)
img = tf.random.normal([1, 224, 224, 3]) # replicating 1 imagenet image
model(img) # (1, 1000)
About the notebooks
perceiver_example
This notebook installs the perceiver
package and shows an example of running it on a single imagenet image ([1, 224, 224, 3]
) with 1000 classes to demonstarte the working of
this model.
Want to Contribute 🙋♂️?
Awesome! If you want to contribute to this project, you're always welcome! See Contributing Guidelines. You can also take a look at open issues for getting more information about current or upcoming tasks.
Want to discuss? 💬
Have any questions, doubts or want to present your opinions, views? You're always welcome. You can start discussions.
Citations
@misc{jaegle2021perceiver,
title = {Perceiver: General Perception with Iterative Attention},
author = {Andrew Jaegle and Felix Gimeno and Andrew Brock and Andrew Zisserman and Oriol Vinyals and Joao Carreira},
year = {2021},
eprint = {2103.03206},
archivePrefix = {arXiv},
primaryClass = {cs.CV}
}
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 perceiver-0.1.2.tar.gz
.
File metadata
- Download URL: perceiver-0.1.2.tar.gz
- Upload date:
- Size: 9.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 41cd564a8c2bf23fa760c7d80bd73908b3882fd86568b00a67bae8d1a3a6c504 |
|
MD5 | 3116c19730a06056783d1b6cfd6174aa |
|
BLAKE2b-256 | f05fa230f8303bdbfef968c2a6e0b312466a2db05687f79f975467db085e796a |
File details
Details for the file perceiver-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: perceiver-0.1.2-py3-none-any.whl
- Upload date:
- Size: 8.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a3c54f267516139714e52c3ca71909c63af1d1d6e5f78b45a124a7fef74a7c71 |
|
MD5 | b8a008248ef3b7ec8d4ddb1c81784831 |
|
BLAKE2b-256 | a7a23f49858bc5ef276b42e2e04fb37ffbcd8d9413ddc93b586c58cea4fa5d67 |