NetModel parameters
This model consists of a family of individual nets, each identified by a specific parameter combination. Inspect the available parameters:
Pick a non-default net by specifying the parameters:
Pick a non-default uninitialized net:
Basic usage
Define a test image:
Answer a question about the image:
Try different questions:
Obtain a test video:
Generate an answer to a question about the video. The answer is generated from a number of uniformly spaced frames whose features are averaged. The number of frames can be controlled via an option:
Feature space visualization
Get a set of images of coffee and ice cream:
Visualize the feature space embedding performed by the image encoder. Notice that images from the same class are clustered together:
Cross-attention visualization for images
When encoding a question, the text encoder attends on the image features produced by the image encoder. Such features are a set of 577 vectors of length 768, where every vector except the first one corresponds to one of 24x24 patches taken from the input image (the extra vector exists because the image encoder inherits the architecture of the image classification model Vision Transformer Trained on ImageNet Competition Data, but in this case, it doesn’t have any special importance). This means that the text encoder attention weights to these image features can be interpreted as the image patches the encoder is "looking at" when generating every new token, and it is possible to visualize this information. Get a test image and compute the features:
Define a question pass it through the text encoder. There are 12 attention blocks in the encoder and each generates its own set of attention weights. Inspect the attention weights for a single block:
Each question's token corresponds to a 12x577 array of attention weights, where 12 is the number of attention heads and 577 is the 24x24 patches plus the extra one:
Extract the attention weights related to the image patches:
Reshape the flat image patch dimension to 24x24 and take the average over the attention heads, thus obtaining a 24x24 attention matrix for each of the eight generated tokens:
To reveal novel patch interactions specific to each token, suppress the consistently high attention weights by subtracting the minimum value aggregated across the token dimension:
Visualize the attention weight matrices. Patches with higher values (red) are what is mostly being "looked at" when generating the corresponding token:
Define a function to visualize the attention matrix on the image:
Visualize the attention mechanism for each token. A recurrent noisy pattern of large positive activation can be observed, but notice the emphasis on the head for the token "boy" and on the hands for "doing":
Net information
Inspect the number of parameters of all arrays in the net:
Obtain the total number of parameters:
Obtain the layer type counts: