NormalizeOp constructor
Initializes a NormalizeOp. When being called, it creates a new TensorBuffer, which satisfies:
output = (input - mean) / stddev
In the following two cases, reset mean
to 0 and stddev
to 1 to bypass the
normalization.
-
Both
mean
andstddev
are 0. -
mean
is 0 andstddev
is Infinity.
Note: If mean
is set to 0 and stddev
is set to 1, no computation will
happen, and original input will be directly returned in execution.
Note: The returned TensorBuffer is always a TfLiteType.float32
tensor at
present, except that the input is a TfLiteType.uint8
tensor, mean
is set to 0 and
stddev
is set to 1.
Throws ArgumentError if stddev
is zero.
Implementation
NormalizeOp(double mean, double stddev) {
if (mean == 0.0 && (stddev == 0.0 || stddev.isInfinite)) {
stddev = 1.0;
}
SupportPreconditions.checkArgument(stddev != 0.0,
errorMessage: "Stddev cannot be zero.");
bool meansIsZeroAndDevsIs1 = false;
if (mean == 0.0 && stddev == 1.0) {
meansIsZeroAndDevsIs1 = true;
}
this.isIdentityOp = meansIsZeroAndDevsIs1;
this.mean = [mean];
this.stddev = [stddev];
this.numChannels = 1;
}