TL;DR
Many networks receive two kinds of input: the data they process, such as an image, and a context that says what to do with it, such as a question about that image. Feature-wise linear modulation, or FiLM, lets the context control the data. A small network reads the context and predicts a scale and a shift for every feature map inside the image network. Each feature map is then multiplied and offset by its numbers, so the same image features can be amplified in one context and suppressed in another.
Where you'll see it: in visual question answering, where one picture must be answered under many different questions, and in style transfer and conditional image generation, where a style or class is supplied as a second input.
Intuition
Start from a familiar situation
A sound engineer has one recording of an orchestra. For a classical broadcast she raises the strings and lowers the drums. For a podcast she pulls the bass down and lifts the voice. The recording is the same. What changes is one fader per track, set according to what the listener needs.
FiLM works the same way inside a network. The image features are the recording. The question sets a fader for each feature map.
Why the context needs to reach inside the network
A simple way to combine a question with an image is to feed both in at the input and let the network sort it out. That works poorly for a long chain of reasoning steps, because the question has to survive every layer and keep telling the image features what to look for. A conditioning signal works better when it acts directly on the internal features, at the layers where the features are being built.
Suppose the question is "is there a red object?" Somewhere inside the network there is a feature map that responds to red. If the question could simply turn that map up, the rest of the network would see a strong red signal and could answer. If the question were "is there a green object?", the same map should be turned down. That is exactly the control FiLM gives.
Turning a context into knobs
Each feature map is one channel of a Convolutional Neural Network: a grid of numbers that is high wherever a particular pattern is present. The question is first turned into a vector of numbers, for example by a Recurrent Neural Network such as a long short-term memory network reading the words one at a time. A linear map then takes that vector and outputs two numbers for every channel: a gain and an offset .
- gamma 1, beta 0 (no change)
- gamma 1.5, beta -1
- gamma 0.5, beta 1
The name says it all. The modulation is feature-wise, because each feature map has its own pair of numbers. It is linear, in the sense that it multiplies and adds, which is the same kind of straight-line rule as .
One knob per channel, not per pixel
The gain and offset are the same at every position in a channel. A red detector is switched up across the whole image, not just in one corner. This keeps the weight sharing of the convolution: the network still looks for a pattern wherever it appears, and the question only decides how much that pattern matters.
flowchart LR Q[Question text] --> E[Encoder, such as an LSTM] E --> V[Question vector] V --> G[FiLM generator] G --> P[Gamma and beta for each channel] I[Image] --> C[Convolution] C --> BN[Batch normalization] BN --> F[FiLM layer] P --> F F --> R[ReLU and the next block]
The math
Setup
Take one layer of an image network. Its output is a stack of feature maps, each of height and width . Write for the value of channel at row and column . The context is a vector , for example the encoding of a question. The FiLM generator is trained together with the rest of the network.
The generator
The generator maps the context to one gain and one offset per channel:
Here and are matrices of size , so that each one multiplies the vector and returns a vector of length . The biases and are also vectors of length . The entry is the gain for channel and is its offset. This is a matrix times vector followed by a shift, which is a linear map plus a constant.
Given a feature map and the gain and offset for its channel, the FiLM layer returns
The rule multiplies each value by its channel's gain and then adds its channel's offset. The map is an affine function: a straight line that need not pass through the origin. The layer has no weights of its own. All of its parameters come from the generator.
Where the layer sits
In the residual blocks used in the original paper, the order is: convolution, then batch normalization, then the FiLM layer, then Rectified Linear Unit (ReLU), and finally the Residual Connection adds the block's input back. Batch normalization has already put each channel on a standard scale. So the gain from the question acts on a predictable range of values, and a gain of 2 always means "double the typical response of this channel".
Starting from no change
If every gain is 1 and every offset is 0, the FiLM layer is the identity and does nothing. Generators are often initialised so that their outputs start close to these values. Training then only has to learn how far to move each channel away from neutral, which makes early training stable.
Cost of the generator
The generator adds parameters, and the cost grows with the context size and the number of channels. For context size and channels, each of and has weights, and each bias vector has 256 entries. One FiLM layer therefore has parameters. Four such layers add up to . That is small next to the image network, but it grows linearly with the number of blocks that are modulated.
Worked examples
One channel of a feature map contains the values , and at three positions. Use gain and offset , with the same numbers at every position.
- Position 1: .
- Position 2: .
- Position 3: .
- Passing the result through Rectified Linear Unit (ReLU) (negative values become 0) gives , and .
Interpretation: the layer doubled every value and moved it up by a half. Because the offset is added after the gain, a value of zero becomes , not zero. The ReLU then removes the negative response at position 2.
A feature map has two channels. The context is . The generator has with bias , and with bias .
Step 1: the gains. .
Step 2: the offsets. .
Step 3: channel 1. Its values are . Apply to each entry: , , , . The result is .
Step 4: channel 2. Its values are . Apply : , , , . The result is .
Interpretation: the question amplified channel 1 (gain 1.5) and weakened channel 2 (gain 0.5). The same two feature maps would have come out differently for a different question, because only changed.
Suppose one channel of a visual reasoning network responds to red colour. On a scene with a red sphere at three positions, its activations are . The values are illustrative, not from a trained model.
- Question: "is there a red object?" The generator produces gain and offset . The modulated values are . The red signal is strengthened, and the rest of the network sees a clear response.
- Question: "is there a green object?" The generator produces gain for this channel. The modulated values are . The red channel is almost silenced, so it cannot distract from the green answer.
Interpretation: nothing about the image changed between the two questions. Only one number per channel changed, and that was enough to shift the network's attention from one colour to the other. This is why FiLM is useful for question answering on a fixed picture.
Tradeoffs and failure modes
FiLM is cheap and simple, and it works best when the conditioning signal tells the network which features matter as a whole. It is weaker when the answer depends on where things are, because a channel gain cannot say "here but not there".
| Situation | Problem | Better choice |
|---|---|---|
| The answer depends on a location, such as "the object to the left of the cube" | A gain is the same at every position, so FiLM cannot select a place | Attention Mechanism over spatial positions, or add coordinate channels to the image |
| The context is a long sentence with many steps | One vector may not hold every detail, and a fixed generator may miss some of them | A stronger encoder such as a Transformer before the generator |
| Only a few discrete conditions, such as a class label | A full generator is more than needed | A lookup table of one gain and offset per class (the simplest form of conditional normalization) |
| Very many modulated layers with wide contexts | The generator's parameter count grows with channels times context size | Share one generator across blocks, or use a low-rank form |
| A gain drifts towards 0 | That channel's output and its gradient both vanish, so it stops learning | Initialise near identity, and monitor the distribution of the generated gains |
Two practical points follow from the math. First, FiLM can only scale and shift what the network has already built. It cannot create a new kind of feature or mix channels together, so the image network must contain the relevant detectors. Second, the gain is multiplicative: a large gain on an already large activation can cause large values and unstable training, which is why normalization such as Batch Normalization or Layer Normalization is usually placed before the FiLM layer.
History
The idea of letting one input set the parameters of a normalization step appeared in several places around 2016 and 2017, each for a different task.
Vincent Dumoulin, Jonathon Shlens and Manjunath Kudlur (2016) trained a network to apply artistic styles. They gave each style its own learned scale and shift inside an instance-normalization step, so the style was a set of channel parameters. This was published as "A Learned Representation for Artistic Style".
Harm de Vries and colleagues (2017) used the same kind of step in a different setting. They used a language representation to set the scale and shift of batch normalization inside a visual network, so that the words of a question could change early visual processing. This was called conditional batch normalization.
Xun Huang and Serge Belongie (2017) introduced adaptive instance normalization for real-time style transfer. Their rule takes the channel means and spreads from a style image and uses them as the new scale and shift for the content image.
Ethan Perez and colleagues (2017, published at AAAI in 2018) gave the general form the name FiLM. They tested it on CLEVR, a synthetic benchmark of 3D shapes with compositional questions, where the questions require counting, comparing and locating objects. Their model reached high accuracy with a simple architecture, and the paper argued that one general layer could replace the separate methods. A 2018 article in Distill by Dumoulin and colleagues later placed these methods in one framework of feature-wise transformations. FiLM caught on because it is a single layer with a clear meaning: the context chooses how much each feature counts.
Recap
FiLM takes a context vector, maps it through a linear generator to a gain and an offset for every channel, and applies to each feature map. The gains and offsets are the same at every position, so the convolutional structure stays intact, and the context decides which features are emphasised. The method is cheap and fits well after Batch Normalization in a residual block. Its main limit is spatial: when the answer depends on where something is, it needs help from attention. It is a natural next step after convolutional networks and word embeddings for multimodal models such as vision-language models.
Check yourself
QuestionIn FiLM, what does each feature map receive from the context, and does the same pair of numbers apply to every position in the channel?Show answer
Each feature map receives a gain and an offset , produced by the generator from the context vector. The same pair applies to every position in channel . The layer computes at each position, so the context changes how strongly each feature is used, not where it is looked for.
QuestionA channel has the values 3, -1 and 0.5. The gain is -2 and the offset is 1. What are the outputs?Show answer
Apply to each value. For : . For : . For : . The outputs are , and .
QuestionWhy does FiLM use one gain and one offset per channel, instead of letting the context produce a full new feature map?Show answer
A full map would need one number for every channel, row and column, which is far more parameters and would need the generator to output a large grid. It would also throw away the weight sharing of the convolution. A per-channel gain and offset is small, keeps the spatial structure of the features, and lets the context choose which features matter, which is the decision that most questions need.
QuestionA model must decide whether a road or a river is present at a given location in a satellite image, and the question says which one to look for. Would FiLM be enough on its own?Show answer
FiLM can strengthen the road-detecting channels for a road question and the river-detecting channels for a river question, which is a good start. But the answer is about location, and a channel gain is the same at every position. If the model must say where the road is, or distinguish a road next to a river, it would need spatial attention or position information as well, and the road and river channels would have to be separate enough for the gains to tell them apart.
Sources
- Perez, Strub, de Vries, Dumoulin and Courville, FiLM: Visual Reasoning with a General Conditioning Layer (2017): https://arxiv.org/abs/1709.07871
- Dumoulin, Perez, Schucher, Strub, de Vries, Courville and Bengio, Feature-wise transformations, Distill (2018): https://distill.pub/2018/feature-wise-transformations/
- Huang and Belongie, Arbitrary Style Transfer in Real-time with Adaptive Instance Normalization (2017): https://arxiv.org/abs/1703.06868
- de Vries, Strub, Mary, Larochelle, Pietquin and Courville, Modulating early visual processing by language (2017): https://arxiv.org/abs/1707.00683