You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Implementation of λ Networks, a new approach to image recognition that reaches SOTA on ImageNet. The new method utilizes λ layer, which captures interactions by transforming contexts into linear functions, termed lambdas, and applying these linear functions to each input separately.
importtorchfromlambda_networksimportLambdaLayerlayer=LambdaLayer(
dim=32, # channels going indim_out=32, # channels outn=64, # size of the receptive window - max(height, width)dim_k=16, # key dimensionheads=4, # number of heads, for multi-querydim_u=1# 'intra-depth' dimension
)
x=torch.randn(1, 32, 64, 64)
layer(x) # (1, 32, 64, 64)
Localized context
importtorchfromlambda_networksimportLambdaLayerlayer=LambdaLayer(
dim=32,
dim_out=32,
r=23, # the receptive field for relative positional encoding (23 x 23)dim_k=16,
heads=4,
dim_u=4
)
x=torch.randn(1, 32, 64, 64)
layer(x) # (1, 32, 64, 64)
For fun, you can also import this as follows
fromlambda_networksimportλLayer
Tensorflow / Keras version
Shinel94 has added a Keras implementation! It won't be officially supported in this repository, so either copy / paste the code under ./lambda_networks/tfkeras.py or make sure to install tensorflow and keras before running the following.