FiLM
This commit is contained in:
parent
f0b828dc4d
commit
aa3edb457c
1 changed files with 16 additions and 0 deletions
16
sCOCA_ML/models/FiLM.py
Normal file
16
sCOCA_ML/models/FiLM.py
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
"""
|
||||||
|
FiLM: Feature-wise Linear Modulation
|
||||||
|
For applying FiLM to condition feature maps on style parameters.
|
||||||
|
"""
|
||||||
|
import torch.nn as nn
|
||||||
|
|
||||||
|
class FiLM(nn.Module):
|
||||||
|
def __init__(self, num_features, style_dim):
|
||||||
|
super(FiLM, self).__init__()
|
||||||
|
self.gamma = nn.Linear(style_dim, num_features)
|
||||||
|
self.beta = nn.Linear(style_dim, num_features)
|
||||||
|
|
||||||
|
def forward(self, x, style):
|
||||||
|
gamma = self.gamma(style).unsqueeze(-1).unsqueeze(-1).unsqueeze(-1)
|
||||||
|
beta = self.beta(style).unsqueeze(-1).unsqueeze(-1).unsqueeze(-1)
|
||||||
|
return gamma * x + beta
|
Loading…
Add table
Add a link
Reference in a new issue