ReduceMean#
Domain:
ai.onnxSince version: 18
Computes the mean of the input tensor’s elements along the provided axes. The resulting tensor has the same rank as the input if keepdims equals 1. If keepdims equals 0, then the resulting tensor has the reduced dimension pruned. The axes are provided as an optional second input tensor. Negative axes are supported. If axes is not provided or is empty and noop_with_empty_axes is set to 1, the input tensor is returned unchanged. If axes is not provided or is empty and noop_with_empty_axes is not set, all dimensions are reduced. Reduction over an empty set of values yields undefined.
Inputs
data (T): An input tensor.
axes (tensor(int64)): Optional input list of integers, along which to reduce. The default is to reduce over all the dimensions of the input tensor if noop_with_empty_axes is false, else act as an Identity op when noop_with_empty_axes is true. Accepted range is [-r, r-1] where r = rank(data).
Outputs
reduced (T): Reduced output tensor.
Attributes
keepdims (int): Keep the reduced dimension or not, default 1 means keep reduced dimension.
noop_with_empty_axes (int): Defines behavior if ‘axes’ is empty. Default behavior with ‘false’ is to reduce all axes. When axes is empty and this attribute is set to true, input tensor will not be reduced, and the output tensor would be equivalent to input tensor.
Type Constraints
T: Constrain input and output types to high-precision numeric tensors. Allowed types: tensor(bfloat16), tensor(double), tensor(float), tensor(float16), tensor(int32), tensor(int64), tensor(uint32), tensor(uint64).
Examples#
test_cc_reducemean_default_axes_keepdims
Node:
ReduceMean(data) -> (reduced)
Attributes:
keepdims = 1
Inputs:
data: shape=(3, 2, 2), dtype=float32
[[[ 1., 2.],
[ 3., 4.]],
[[ 5., 6.],
[ 7., 8.]],
[[ 9., 10.],
[11., 12.]]]
Outputs:
reduced: shape=(1, 1, 1), dtype=float32
[[[6.5]]]
test_cc_reducemean_do_not_keepdims
Node:
ReduceMean(data, axes) -> (reduced)
Attributes:
keepdims = 0
Inputs:
data: shape=(3, 2, 2), dtype=float32
[[[ 1., 2.],
[ 3., 4.]],
[[ 5., 6.],
[ 7., 8.]],
[[ 9., 10.],
[11., 12.]]]
axes: shape=(1,), dtype=int64
[1]
Outputs:
reduced: shape=(3, 2), dtype=float32
[[ 2., 3.],
[ 6., 7.],
[10., 11.]]
test_cc_reducemean_empty_axes_input_noop
Node:
ReduceMean(data, axes) -> (reduced)
Attributes:
keepdims = 1
noop_with_empty_axes = 1
Inputs:
data: shape=(3, 2, 2), dtype=float32
[[[ 1., 2.],
[ 3., 4.]],
[[ 5., 6.],
[ 7., 8.]],
[[ 9., 10.],
[11., 12.]]]
axes: shape=(0,), dtype=int64
[]
Outputs:
reduced: shape=(3, 2, 2), dtype=float32
[[[ 1., 2.],
[ 3., 4.]],
[[ 5., 6.],
[ 7., 8.]],
[[ 9., 10.],
[11., 12.]]]
test_cc_reducemean_keepdims
Node:
ReduceMean(data, axes) -> (reduced)
Attributes:
keepdims = 1
Inputs:
data: shape=(3, 2, 2), dtype=float32
[[[ 1., 2.],
[ 3., 4.]],
[[ 5., 6.],
[ 7., 8.]],
[[ 9., 10.],
[11., 12.]]]
axes: shape=(1,), dtype=int64
[1]
Outputs:
reduced: shape=(3, 1, 2), dtype=float32
[[[ 2., 3.]],
[[ 6., 7.]],
[[10., 11.]]]
test_cc_reducemean_negative_axes_keepdims
Node:
ReduceMean(data, axes) -> (reduced)
Attributes:
keepdims = 1
Inputs:
data: shape=(3, 2, 2), dtype=float32
[[[ 1., 2.],
[ 3., 4.]],
[[ 5., 6.],
[ 7., 8.]],
[[ 9., 10.],
[11., 12.]]]
axes: shape=(1,), dtype=int64
[-2]
Outputs:
reduced: shape=(3, 1, 2), dtype=float32
[[[ 2., 3.]],
[[ 6., 7.]],
[[10., 11.]]]
test_cc_shape_inference_loop_topk_pairwise_distance
Node:
ReduceMean(topk_values, mean_axes) -> (Y)
Attributes:
keepdims = 0
Inputs:
topk_values: shape=(3, 4), dtype=float32
[[0., 0., 0., 0.],
[3., 0., 0., 0.],
[0., 4., 0., 0.]]
mean_axes: shape=(1,), dtype=int64
[2]
Outputs:
Y: shape=(3,), dtype=float32
[3.5, 4. , 4.5]
test_cc_shape_inference_pad_canny_average
Node:
ReduceMean(filtered, axes_mean) -> (avg)
Attributes:
keepdims = 1
Inputs:
filtered: shape=(2, 1, 5, 7), dtype=float32
[[[[ 1., 2., 3., ..., 5., 6., 7.],
[ 8., 9., 10., ..., 12., 13., 14.],
[15., 16., 17., ..., 19., 20., 21.],
[22., 23., 24., ..., 26., 27., 28.],
[29., 30., 31., ..., 33., 34., 35.]]],
[[[36., 37., 38., ..., 40., 41., 42.],
[43., 44., 45., ..., 47., 48., 49.],
[50., 51., 52., ..., 54., 55., 56.],
[57., 58., 59., ..., 61., 62., 63.],
[64., 65., 66., ..., 68., 69., 70.]]]]
Outputs:
avg: shape=(2, 1, 5, 7), dtype=float32
[[[[-16., -14., -14., ..., -14., -14., -12.],
[ -2., 0., 0., ..., 0., 0., 2.],
[ -2., 0., 0., ..., 0., 0., 2.],
[ -2., 0., 0., ..., 0., 0., 2.],
[ 12., 14., 14., ..., 14., 14., 16.]]],
[[[-16., -14., -14., ..., -14., -14., -12.],
[ -2., 0., 0., ..., 0., 0., 2.],
[ -2., 0., 0., ..., 0., 0., 2.],
[ -2., 0., 0., ..., 0., 0., 2.],
[ 12., 14., 14., ..., 14., 14., 16.]]]]
test_cc_shape_inference_scan_topk_pairwise_distance
Node:
ReduceMean(topk_values, mean_axes) -> (Y)
Attributes:
keepdims = 0
Inputs:
topk_values: shape=(3, 4), dtype=float32
[[0., 0., 0., 0.],
[3., 0., 0., 0.],
[0., 4., 0., 0.]]
mean_axes: shape=(1,), dtype=int64
[2]
Outputs:
Y: shape=(3,), dtype=float32
[3.5, 4. , 4.5]
test_cc_shape_inference_topk_pairwise_distance
Node:
ReduceMean(topk_values, mean_axes) -> (Y)
Attributes:
keepdims = 0
Inputs:
topk_values: shape=(3, 3), dtype=float32
[[0., 0., 0.],
[3., 0., 0.],
[0., 4., 0.]]
mean_axes: shape=(1,), dtype=int64
[2]
Outputs:
Y: shape=(3,), dtype=float32
[3.5, 4. , 4.5]
test_cc_shape_inference_two_topk_different_k
Node:
ReduceMean(values2, mean_axes) -> (Y)
Attributes:
keepdims = 0
Inputs:
values2: shape=(3, 5), dtype=float32
[[ 5., 4., 3., 2., 1.],
[10., 9., 8., 7., 6.],
[15., 14., 13., 12., 11.]]
mean_axes: shape=(1,), dtype=int64
[3]
input_2: shape=(1,), dtype=int64
[2]
Outputs:
Y: shape=(3,), dtype=float32
[ 4.5, 9.5, 14.5]
test_cc_shape_inference_two_topk_same_k
Node:
ReduceMean(values2, mean_axes) -> (Y)
Attributes:
keepdims = 0
Inputs:
values2: shape=(3, 5), dtype=float32
[[ 5., 4., 3., 2., 1.],
[10., 9., 8., 7., 6.],
[15., 14., 13., 12., 11.]]
mean_axes: shape=(1,), dtype=int64
[2]
Outputs:
Y: shape=(3,), dtype=float32
[ 4.5, 9.5, 14.5]
test_reduce_mean_default_axes_keepdims_example
Node:
ReduceMean(data) -> (reduced)
Attributes:
keepdims = 1
Inputs:
data: shape=(3, 2, 2), dtype=float32
[[[ 1., 2.],
[ 3., 4.]],
[[ 5., 6.],
[ 7., 8.]],
[[ 9., 10.],
[11., 12.]]]
Outputs:
reduced: shape=(1, 1, 1), dtype=float32
[[[6.5]]]
test_reduce_mean_default_axes_keepdims_random
Node:
ReduceMean(data) -> (reduced)
Attributes:
keepdims = 1
Inputs:
data: shape=(3, 2, 2), dtype=float32
[[[ 0.9762701 , 4.303787 ],
[ 2.0552676 , 0.89766365]],
[[-1.526904 , 2.9178822 ],
[-1.2482557 , 7.83546 ]],
[[ 9.273255 , -2.3311696 ],
[ 5.834501 , 0.5778984 ]]]
Outputs:
reduced: shape=(1, 1, 1), dtype=float32
[[[2.463805]]]
test_reduce_mean_do_not_keepdims_example
Node:
ReduceMean(data, axes) -> (reduced)
Attributes:
keepdims = 0
Inputs:
data: shape=(3, 2, 2), dtype=float32
[[[ 1., 2.],
[ 3., 4.]],
[[ 5., 6.],
[ 7., 8.]],
[[ 9., 10.],
[11., 12.]]]
axes: shape=(1,), dtype=int64
[1]
Outputs:
reduced: shape=(3, 2), dtype=float32
[[ 2., 3.],
[ 6., 7.],
[10., 11.]]
test_reduce_mean_do_not_keepdims_random
Node:
ReduceMean(data, axes) -> (reduced)
Attributes:
keepdims = 0
Inputs:
data: shape=(3, 2, 2), dtype=float32
[[[ 0.9762701 , 4.303787 ],
[ 2.0552676 , 0.89766365]],
[[-1.526904 , 2.9178822 ],
[-1.2482557 , 7.83546 ]],
[[ 9.273255 , -2.3311696 ],
[ 5.834501 , 0.5778984 ]]]
axes: shape=(1,), dtype=int64
[1]
Outputs:
reduced: shape=(3, 2), dtype=float32
[[ 1.5157688, 2.6007254],
[-1.3875799, 5.3766713],
[ 7.553878 , -0.8766356]]
test_reduce_mean_keepdims_example
Node:
ReduceMean(data, axes) -> (reduced)
Attributes:
keepdims = 1
Inputs:
data: shape=(3, 2, 2), dtype=float32
[[[ 1., 2.],
[ 3., 4.]],
[[ 5., 6.],
[ 7., 8.]],
[[ 9., 10.],
[11., 12.]]]
axes: shape=(1,), dtype=int64
[1]
Outputs:
reduced: shape=(3, 1, 2), dtype=float32
[[[ 2., 3.]],
[[ 6., 7.]],
[[10., 11.]]]
test_reduce_mean_keepdims_random
Node:
ReduceMean(data, axes) -> (reduced)
Attributes:
keepdims = 1
Inputs:
data: shape=(3, 2, 2), dtype=float32
[[[ 0.9762701 , 4.303787 ],
[ 2.0552676 , 0.89766365]],
[[-1.526904 , 2.9178822 ],
[-1.2482557 , 7.83546 ]],
[[ 9.273255 , -2.3311696 ],
[ 5.834501 , 0.5778984 ]]]
axes: shape=(1,), dtype=int64
[1]
Outputs:
reduced: shape=(3, 1, 2), dtype=float32
[[[ 1.5157688, 2.6007254]],
[[-1.3875799, 5.3766713]],
[[ 7.553878 , -0.8766356]]]
test_reduce_mean_negative_axes_keepdims_example
Node:
ReduceMean(data, axes) -> (reduced)
Attributes:
keepdims = 1
Inputs:
data: shape=(3, 2, 2), dtype=float32
[[[ 1., 2.],
[ 3., 4.]],
[[ 5., 6.],
[ 7., 8.]],
[[ 9., 10.],
[11., 12.]]]
axes: shape=(1,), dtype=int64
[-2]
Outputs:
reduced: shape=(3, 1, 2), dtype=float32
[[[ 2., 3.]],
[[ 6., 7.]],
[[10., 11.]]]
test_reduce_mean_negative_axes_keepdims_random
Node:
ReduceMean(data, axes) -> (reduced)
Attributes:
keepdims = 1
Inputs:
data: shape=(3, 2, 2), dtype=float32
[[[ 0.9762701 , 4.303787 ],
[ 2.0552676 , 0.89766365]],
[[-1.526904 , 2.9178822 ],
[-1.2482557 , 7.83546 ]],
[[ 9.273255 , -2.3311696 ],
[ 5.834501 , 0.5778984 ]]]
axes: shape=(1,), dtype=int64
[-2]
Outputs:
reduced: shape=(3, 1, 2), dtype=float32
[[[ 1.5157688, 2.6007254]],
[[-1.3875799, 5.3766713]],
[[ 7.553878 , -0.8766356]]]
Differences with previous version (13)#
SchemaDiff: ReduceMean (domain 'ai.onnx')
old version: 13
new version: 18
breaking: yes
Breaking reasons:
input ‘axes’ (added): at position 1; option=Single; type_str=’tensor(int64)’
attribute ‘axes’ (removed): type=INTS; required=False
Inputs:
[BREAKING] added ‘axes’: at position 1; option=Single; type_str=’tensor(int64)’
Attributes:
[BREAKING] removed ‘axes’: type=INTS; required=False
added ‘noop_with_empty_axes’: type=INT; required=False; default=0
Documentation:
line similarity: 0.62 (+3/-2 lines)
--- ReduceMean v13
+++ ReduceMean v18
@@ -1,6 +1,7 @@
Computes the mean of the input tensor's elements along the provided axes.
The resulting tensor has the same rank as the input if keepdims equals 1.
If keepdims equals 0, then the resulting tensor has the reduced dimension pruned.
-The axes attribute specifies which dimensions to reduce. Negative axes are supported.
-If axes is not provided, all dimensions are reduced.
+The axes are provided as an optional second input tensor. Negative axes are supported.
+If axes is not provided or is empty and noop_with_empty_axes is set to 1, the input tensor is returned unchanged.
+If axes is not provided or is empty and noop_with_empty_axes is not set, all dimensions are reduced.
Reduction over an empty set of values yields undefined.