OpenViSTAI · Agents · Blockchain · Crypto
Menu
AI Models

Bottleneck Transformer Pytorch

A Python library implementing a PyTorch BottleStack layer that combines convolution and attention for visual-recognition models.

Independent OpenViST project profile, based on linked sources.

Bottleneck Transformer Pytorch — OpenViST project profile in AI Models.
OpenViST project illustration. See the linked sources for product details.
Understand the project

Practical overview

When it fits

Use it when building a PyTorch visual-recognition model and you want a documented convolution-and-attention layer that can be placed in a ResNet-style feature stack.

Who it is for

  • PyTorch developers building image-classification or other visual-recognition models.
  • Researchers and practitioners adapting ResNet-style backbones with a bottleneck transformer layer.

Documented uses

  • Insert a BottleStack layer into a model that processes image feature maps.
  • Replace part of a ResNet-50 backbone to assemble the documented BotNet-style image classifier.
  • Configure channel dimensions, feature-map size, attention heads, downsampling and positional embeddings for the inserted layer.
Before you choose

Requirements & limits

The public GitHub repository lists an MIT license and provides a pip installation command.

  • BottleStack operates on feature maps; the caller must configure dimensions to match the model stage.
  • The README's standalone example uses absolute positional embeddings by setting rel_pos_emb to false, while the ResNet-50 example enables relative positional embeddings.
  • The documented ResNet-50 integration uses torchvision and a 224-by-224 image input.

Check current requirements in the official documentation. Source-based guidance does not mean OpenViST has run or independently tested this project.

Source-based practical guide

Add BottleStack to a ResNet-50 classifier

Construct the documented BotNet-style model that replaces part of a ResNet-50 backbone with BottleStack.

Before you start

  • Python with PyTorch and torchvision available.
  • The bottleneck-transformer-pytorch package installed.
  • A ResNet-50 backbone and input images sized 224 by 224, as used in the example.

Steps

  1. Import torch, torch.nn, torchvision.models.resnet50 and BottleStack.

  2. Configure BottleStack with dim 256, fmap_size 56, dim_out 2048, proj_factor 4, downsample enabled, four heads, dim_head 128, relative positional embeddings enabled and ReLU activation.

  3. Create resnet50, take its first five children, and place those layers followed by BottleStack, adaptive average pooling, flattening and a 2048-to-1000 linear layer in nn.Sequential.

  4. Pass a batch-shaped image tensor with the example shape (2, 3, 224, 224) to the model.

Expected outcome

The README's example produces a prediction tensor shaped (2, 1000).

Guide limitations

  • The example shows model assembly and a forward pass, not a training loop or dataset setup.
Evidence and transparency

Sources & review

Source record details
Source availability
Active
Sources checked
16 October 2026
Original website title
lucidrains/bottleneck-transformer-pytorch · Official homepage title · retained in its source language