peal.architectures.basic_modules.DimensionSwitchAttentionLayer¶
- class peal.architectures.basic_modules.DimensionSwitchAttentionLayer[source]¶
Bases:
ModuleCross-attention that maps a spatial feature map to
output_sizeslots.A fixed random lookup table of
output_sizequery vectors attends over the flattened, coordinate-augmented input positions, so the spatial axis is replaced by a learned-query axis of fixed length. The table is created as atorch.autograd.Variablerather than annn.Parameter, so it is neither trained nor stored instate_dict.- Parameters:
Methods
Cross-attend the lookup queries over the positions of
x.- forward(x)[source]¶
Cross-attend the lookup queries over the positions of
x.- Parameters:
x (
torch.Tensor) – Shape(B, C, *spatial).- Returns:
Shape
(B, num_hidden - len(spatial), output_size)after the coordinate channels are removed and the axes transposed.- Return type: