Package: perceiver
PerceiverThis Python package implementsPerceiver: General Perception with Iterative Attentionby 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'svideowas very helpful.InstallationRun the following to install:pipinstallperceiverDevelopingperceiverTo installperceiver, along with tools you need to develop and test, run the following in your virtualenv:gitclonehttps://github.com/Rishit-dagli/Perceiver.git# or clone your own forkcdperceiver
pipinstall-e.[dev]A bit about PerceiverThe 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.UsagefromperceiverimportPerceiverimporttensorflowastfmodel=Perceiver(input_channels=3,# number of channels for each token of the inputinput_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 isdepth=6,# depth of netnum_latents=256,# number of latentslatent_dim=512,# latent dimensioncross_heads=1,# number of heads for cross attention. paper said 1latent_heads=8,# number of heads for latent self attention, 8cross_dim_head=64,latent_dim_head=64,num_classes=1000,# output number of classesattn_dropout=0.,ff_dropout=0.,)img=tf.random.normal([1,224,224,3])# replicating 1 imagenet imagemodel(img)# (1, 1000)About the notebooksperceiver_exampleThis notebook installs theperceiverpackage 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! SeeContributing Guidelines. You can also take a look atopen issuesfor 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 canstart 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}}