learning.NeighborhoodAttention3d#
- class bartorch.learning.NeighborhoodAttention3d#
Bases:
ModuleMulti-head neighbourhood attention over
(n, channels, z, y, x)feature maps.Queries, keys and values are 1-wide convolutions of the input, each head attends over the
window^3voxels around each voxel with a learned bias for each relative position, and a 1-wide convolution mixes the heads. The cost is linear in the volume,window^3times that of a 1-wide convolution, against the square of the volume for full attention.- Parameters:
channels (int) – Input and output channels.
heads (int, default=None) – Heads;
channelssplit into heads of 16 when omitted, or one head for fewer than 16 channels.window (int, default=5) – Odd edge of each voxel’s window, at most 9.
Examples
>>> block = learning.NeighborhoodAttention3d(32, window=5) >>> features = features + block(features)
- forward()#
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.