Out-of-distribution detection using a neural network
Features extracted from one or more layers of a trained deep neural network (DNN) are used to detect out-of-distribution (OOD) data, such as anomalies. An OOD detection process includes transforming a feature output from a layer of the DNN from a relatively high-dimensional feature space to a lower-dimensional space, and then performing a reverse transformation back to the higher-dimensional feature space, resulting in a reconstructed feature. A feature reconstruction error is calculated based on a difference between the reconstructed feature and the original feature output from the DNN. The OOD detection process may further include calculating a score based on the feature reconstruction error and generating a visual representation of the feature reconstruction error.
1 . A computer-implemented method, comprising:
receiving an output feature map output by an intermediate layer of a neural network, the neural network comprising a first layer to receive a representation of an input image and at least one intermediate layer following the first layer;
applying a forward transformation to the output feature map to generate an embedding, the forward transformation reducing a dimensionality of the output feature map, wherein applying the forward transformation to the output feature map to generate the embedding comprises vectorizing the output feature map to generate a vectorized feature, the vectorized feature having a lower rank than the output feature map, and reducing a dimensionality of the vectorized feature to generate the embedding, wherein the embedding has fewer elements than the vectorized feature;
performing a reverse transformation of the embedding to generate a reconstructed feature map, the reconstructed feature map having a same dimensionality as the output feature map;
determining a feature reconstruction error representing a difference between the output feature map and the reconstructed feature map; and
determining a detection score based on the feature reconstruction error, the detection score indicating whether the input image includes out-of-distribution data.
2 . The computer-implemented method of claim 1 , wherein applying the forward transformation to the output feature map to generate the embedding comprises:
performing an orthogonal linear transformation on the output feature map, the orthogonal linear transformation calculated from a training dataset using principal component analysis.
3 . The computer-implemented method of claim 1 , wherein applying the forward transformation to the output feature map to generate the embedding comprises:
applying a transformation learned from a training dataset using a nonlinear manifold learning technique.
4 . The computer-implemented method of claim 1 , wherein performing the reverse transformation of the embedding comprises:
applying a pseudo-inverse of the forward transformation to the embedding, wherein the pseudo-inverse has a same dimensionality as the output feature map.
5 . The computer-implemented method of claim 1 , the method further comprising:
generating a localization map of the feature reconstruction error, the localization map having dimensions corresponding to the input image, the localization map indicating where, in the input image, the out-of-distribution data is located.
6 . The computer-implemented method of claim 5 , wherein the feature reconstruction error is an error vector, and generating the localization map of the feature reconstruction error comprises:
rearranging the error vector to an error tensor, the error tensor having a same dimension as the output feature map;
performing a channel-wise averaging of the error tensor to generate the localization map; and
resizing the localization map to match the dimensions of the input image.
7 . The computer-implemented method of claim 5 , the method further comprising:
determining a second feature reconstruction error based on a second output feature map, the second output feature map obtained from an output of a second intermediate layer of the neural network;
generating a second localization map of the second feature reconstruction error; and
combining the localization map and the second localization map into a combined error localization map.
8 . The computer-implemented method of claim 7 , wherein combining the localization map and the second localization map comprises calculating a pixel-wise geometric average of the localization map and the second localization map.
9 . One or more non-transitory computer-readable media storing instructions executable to perform operations, the operations comprising:
receiving an output feature map output by an intermediate layer of a neural network, the neural network comprising a first layer to receive a representation of an input image and at least one intermediate layer following the first layer;
applying a forward transformation to the output feature map to generate an embedding, the forward transformation reducing a dimensionality of the output feature map, wherein applying the forward transformation to the output feature map to generate the embedding comprises vectorizing the output feature map to generate a vectorized feature, the vectorized feature having a lower rank than the output feature map, and reducing a dimensionality of the vectorized feature to generate the embedding, wherein the embedding has fewer elements than the vectorized feature;
performing a reverse transformation of the embedding to generate a reconstructed feature map, the reconstructed feature map having a same dimensionality as the output feature map;
determining a feature reconstruction error representing a difference between the output feature map and the reconstructed feature map; and
determining a detection score based on the feature reconstruction error, the detection score indicating whether the input image includes out-of-distribution data.
10 . The one or more non-transitory computer-readable media of claim 9 , wherein applying the forward transformation to the output feature map to generate the embedding comprises:
performing an orthogonal linear transformation on the output feature map, the orthogonal linear transformation calculated from a training dataset using principal component analysis.
11 . The one or more non-transitory computer-readable media of claim 9 , wherein applying the forward transformation to the output feature map to generate the embedding comprises:
applying a transformation learned from a training dataset using a nonlinear manifold learning technique.
12 . The one or more non-transitory computer-readable media of claim 9 , wherein performing the reverse transformation of the embedding comprises:
applying a pseudo-inverse of the forward transformation to the embedding, wherein the pseudo-inverse has a same dimensionality as the output feature map.
13 . The one or more non-transitory computer-readable media of claim 9 , the operations further comprising:
generating a localization map of the feature reconstruction error, the localization map having dimensions corresponding to the input image, the localization map indicating where, in the input image, the out-of-distribution data is located.
14 . The one or more non-transitory computer-readable media of claim 13 , wherein the feature reconstruction error is an error vector, and generating the localization map of the feature reconstruction error comprises:
rearranging the error vector to an error tensor, the error tensor having a same dimension as the output feature map;
performing a channel-wise averaging of the error tensor to generate the localization map; and
resizing the localization map to match the dimensions of the input image.
15 . The one or more non-transitory computer-readable media of claim 13 , the operations further comprising:
determining a second feature reconstruction error based on a second output feature map, the second output feature map obtained from an output of a second intermediate layer of the neural network;
generating a second localization map of the second feature reconstruction error; and
combining the localization map and the second localization map into a combined error localization map.
16 . The one or more non-transitory computer-readable media of claim 15 , wherein combining the localization map and the second localization map comprises calculating a pixel-wise geometric average of the localization map and the second localization map.
17 . An apparatus, comprising:
a computer processor for executing computer program instructions; and
a computer-readable memory storing computer program instructions executable by the computer processor to perform operations comprising:
receiving an output feature map output by an intermediate layer of a neural network, the neural network comprising a first layer to receive a representation of an input image and at least one intermediate layer following the first layer;
applying a forward transformation to the output feature map to generate an embedding, the forward transformation reducing a dimensionality of the output feature map, wherein applying the forward transformation to the output feature map to generate the embedding comprises vectorizing the output feature map to generate a vectorized feature, the vectorized feature having a lower rank than the output feature map, and reducing a dimensionality of the vectorized feature to generate the embedding, wherein the embedding has fewer elements than the vectorized feature;
performing a reverse transformation of the embedding to generate a reconstructed feature map, the reconstructed feature map having a same dimensionality as the output feature map;
determining a feature reconstruction error representing a difference between the output feature map and the reconstructed feature map; and
determining a detection score based on the feature reconstruction error, the detection score indicating whether the input image includes out-of-distribution data.
18 . The apparatus of claim 17 , the operations further comprising:
generating a localization map of the feature reconstruction error, the localization map having dimensions corresponding to the input image, the localization map indicating where, in the input image, the out-of-distribution data is located.
19 . The apparatus of claim 17 , the operations further comprising:
generating a localization map of the feature reconstruction error, the localization map having dimensions corresponding to the input image, the localization map indicating where, in the input image, the out-of-distribution data is located.
20 . The apparatus of claim 19 , wherein the feature reconstruction error is an error vector, and generating the localization map of the feature reconstruction error comprises:
rearranging the error vector to an error tensor, the error tensor having a same dimension as the output feature map;
performing a channel-wise averaging of the error tensor to generate the localization map; and
resizing the localization map to match the dimensions of the input image.