lambda networks
0.4.0
實作 λ Networks,這是一種新的影像辨識方法,在 ImageNet 上達到了 SOTA。新方法利用 λ 層,該層透過將上下文轉換為線性函數(稱為 lambda)並將這些線性函數分別應用於每個輸入來捕獲交互作用。
Yannic Kilcher 的論文評論
$ pip install lambda-networks
全球背景
import torch
from lambda_networks import LambdaLayer
layer = LambdaLayer (
dim = 32 , # channels going in
dim_out = 32 , # channels out
n = 64 , # size of the receptive window - max(height, width)
dim_k = 16 , # key dimension
heads = 4 , # number of heads, for multi-query
dim_u = 1 # 'intra-depth' dimension
)
x = torch . randn ( 1 , 32 , 64 , 64 )
layer ( x ) # (1, 32, 64, 64)
本地化上下文
import torch
from lambda_networks import LambdaLayer
layer = 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)
為了好玩,您還可以如下匯入它
from lambda_networks import λLayer
Shinel94 新增了 Keras 實作!此儲存庫不會正式支援它,因此請將程式碼複製/貼上到./lambda_networks/tfkeras.py
下,或確保在執行以下命令之前安裝tensorflow
和keras
。
import tensorflow as tf
from lambda_networks . tfkeras import LambdaLayer
layer = LambdaLayer (
dim_out = 32 ,
r = 23 ,
dim_k = 16 ,
heads = 4 ,
dim_u = 1
)
x = tf . random . normal (( 1 , 64 , 64 , 16 )) # channel last format
layer ( x ) # (1, 64, 64, 32)
@inproceedings {
anonymous2021lambdanetworks,
title = { LambdaNetworks: Modeling long-range Interactions without Attention } ,
author = { Anonymous } ,
booktitle = { Submitted to International Conference on Learning Representations } ,
year = { 2021 } ,
url = { https://openreview.net/forum?id=xTJEN-ggl1b } ,
note = { under review }
}