MeanVarianceNormalization CPU EP axes attribute validation (#11925)

Validate axes attribute parameter properly rather than silently returning incorrect results
This commit is contained in:
Dwayne Robinson 2022-06-22 12:03:13 -07:00 committed by GitHub
parent f54476a42f
commit f6d2fe8311
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -105,10 +105,15 @@ class MeanVarianceNormalization_1 final : public MeanVarianceNormalization_0<T>
if (!info.GetAttrs("axes", axes).IsOK()) {
axes = {0, 2, 3};
}
if (find(axes.begin(), axes.end(), 1) != axes.end()) {
constexpr int64_t cross_channel_axes[] = {0, 1, 2, 3};
constexpr int64_t batch_spatial_axes[] = {0, 2, 3};
if (std::equal(std::begin(axes), std::end(axes), std::begin(cross_channel_axes), std::end(cross_channel_axes))) {
this->across_channels_ = true;
} else {
} else if (std::equal(std::begin(axes), std::end(axes), std::begin(batch_spatial_axes), std::end(batch_spatial_axes))) {
this->across_channels_ = false;
} else {
ORT_THROW("MeanVarianceNormalization CPU EP only supports NHW and NCHW reduction for axes attribute.");
}
this->normalize_variance_ = 1;
}