After Normalizer why was mean calculated. #147
Replies: 1 comment
-
Thank you for your question. The purpose of the mean(2) function in this code is to reduce the dimensionality of the feature data for use in the k-nearest neighbors algorithm. The feature data is first extracted from the neural network and reshaped into a 3D tensor with dimensions (batch_size, dim, n^2). The mean(2) function is then applied to this tensor to calculate the mean value along the third axis, which results in a 2D tensor with dimensions (batch_size, dim). This process effectively reduces the feature dimensionality from n^2 to dim, making it more suitable for use in the k-nearest neighbors algorithm. For ResNet, which uses nn.AdaptiveAvgPool2d((1, 1)) for its last layer, the feature size is always (batch_size, dim, 1, 1). In this case, mean() is equivalent to squeeze() since there is only one value along the third axis. However, for other cases where the feature size of the last layer is not (dim, 1, 1), mean() is used to reduce the dimensionality. Please let us know if you have any further questions or concerns. |
Beta Was this translation helpful? Give feedback.
-
https://github.com/Jingkang50/OpenOOD/blob/e640ffe2f17aaaad0fc1f937736122d8d5c5cd7b/openood/postprocessors/knn_postprocessor.py
Referring to the line # 39.
activation_log.append(
normalizer(feature.data.cpu().numpy().reshape(
batch_size, dim, -1).mean(2)))
After the features are normalized I am not able to understand why was mean calculated? Thanks!
Beta Was this translation helpful? Give feedback.
All reactions