braindecode.visualization.layer_grad_cam#
- braindecode.visualization.layer_grad_cam(model, x, target, layer)[source]#
Compute a class activation map at a convolutional layer with Captum.
A layer with a three-dimensional output
(batch, features, length), such as a temporal convolution, gives one map per trial of shape(batch, n_times): its last axis, which must be time, is linearly interpolated ton_times. A layer with a four-dimensional output(batch, features, channels, time)gives a map of shape(batch, n_chans, n_times): its two last axes are bilinearly interpolated to(n_chans, n_times). Its channel axis must holdn_chansentries, or one once the layer has mixed the channels, and its time axis more than one step; otherwise aValueErrornames the layer. This rejects the layers ofShallowFBCSPNetandDeep4Netafter theirdimshuffle, which hold time on the height axis. Token sequences of transformers hold tokens on the features axis, so their maps are not maps over time. Localization is limited by the resolution of the selected layer.