Self Attentionのメカニズムについて理解したい
pythonのコードからSelf Attentionのメカニズムについて理解したい。
前提
pythonのコードからSelf Attentionのメカニズムについて理解しようとしています。
ただ、Self Attentionの部分が1行で済まされているのでなかなかイメージが掴めません。
今のところ、該当のコードは単なる多重パーセプトロンで処理がされていると思いますが、
Self Attention = 多重パーセプトロン
なのでしょうか?
入力は動画のフレーム画像から抽出した3次元のテンソルとなります。
有識者の方々、ご教授いただけると幸いです。
該当のソースコード
python
1class VideoClassifier(nn.Module): 2 def __init__(self,args,r=3,da=64,attention=False): 3 super().__init__() 4 self.self_anttention = nn.Sequential(nn.Linear(args.feature_size,da),nn.Tanh(),nn.Linear(da,r)) 5 self.fc1 = nn.Linear(args.feature_size*r,32) 6 self.fc2 = nn.Linear(32,1) 7 self.dropout = nn.Dropout(0.3) 8 self.sig = nn.Sigmoid() 9 10 self.return_attention = attention 11 12 def forward(self,x): 13 bs,t,f = x.shape 14 attentionweight = self.dropout(F.softmax(self.self_anttention(x),dim=1)) 15 m = torch.bmm(x.permute(0,2,1),attentionweight) 16 x = m.view(bs,-1) 17 x = self.fc1(x) 18 x = self.fc2(x) 19 x = self.sig(x) 20 x = x.view(bs) #[batch] 21 22 if self.return_attention: 23 return x, attentionweight 24 else: 25 return x
試したこと
ここに問題に対して試したことを記載してください。
補足情報(FW/ツールのバージョンなど)
このコードのURLです。
https://github.com/yaegasikk/attention_anomaly_detector/

バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2023/09/30 09:03
2023/09/30 09:48
2023/10/01 06:41
2023/10/01 10:12
2023/10/02 01:54 編集
2023/10/03 14:05
2023/10/03 16:05 編集
2023/10/11 05:20
2023/10/11 05:48
2023/10/15 13:31
2023/10/15 17:12
2023/10/16 06:02
2023/10/16 06:39
2023/10/16 11:08
2023/10/16 13:24
2023/10/18 07:40
2023/10/18 08:11
2023/10/18 12:18
2023/10/19 00:54
2023/10/19 05:05
2023/10/19 05:41
2023/11/01 08:07
2023/11/01 08:33
2023/11/01 09:29
2023/11/01 13:14
2023/11/01 16:50 編集