Unsqueeze#
Unsqueeze - 13#
Version
name: Unsqueeze (GitHub)
domain: main
since_version: 13
function: False
support_level: SupportType.COMMON
shape inference: True
This version of the operator has been available since version 13.
Summary
Insert single-dimensional entries to the shape of an input tensor (data). Takes one required input axes - which contains a list of dimension indices and this operator will insert a dimension of value 1 into the corresponding index of the output tensor (expanded).
- For example:
Given an input tensor (data) of shape [3, 4, 5], then Unsqueeze(data, axes=[0, 4]) outputs a tensor (expanded) containing same data as data but with shape [1, 3, 4, 5, 1].
The input axes should not contain any duplicate entries. It is an error if it contains duplicates. The rank of the output tensor (output_rank) is the rank of the input tensor (data) plus the number of values in axes. Each value in axes should be within the (inclusive) range [-output_rank , output_rank - 1]. The order of values in axes does not matter and can come in any order.
Inputs
data (heterogeneous) - T: Original tensor
axes (heterogeneous) - tensor(int64): List of integers indicating the dimensions to be inserted. Negative value means counting dimensions from the back. Accepted range is [-r, r-1] where r = rank(expanded).
Outputs
expanded (heterogeneous) - T: Reshaped tensor with same data as input.
Type Constraints
T in ( tensor(bfloat16), tensor(bool), tensor(complex128), tensor(complex64), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8) ): Constrain input and output types to all tensor types.
Examples
unsqueeze_one_axis
x = np.random.randn(3, 4, 5).astype(np.float32)
for i in range(x.ndim):
axes = np.array([i]).astype(np.int64)
node = onnx.helper.make_node(
'Unsqueeze',
inputs=['x', 'axes'],
outputs=['y'],
)
y = np.expand_dims(x, axis=i)
expect(node, inputs=[x, axes], outputs=[y],
name='test_unsqueeze_axis_' + str(i))
unsqueeze_two_axes
x = np.random.randn(3, 4, 5).astype(np.float32)
axes = np.array([1, 4]).astype(np.int64)
node = onnx.helper.make_node(
'Unsqueeze',
inputs=['x', 'axes'],
outputs=['y'],
)
y = np.expand_dims(x, axis=1)
y = np.expand_dims(y, axis=4)
expect(node, inputs=[x, axes], outputs=[y],
name='test_unsqueeze_two_axes')
unsqueeze_three_axes
x = np.random.randn(3, 4, 5).astype(np.float32)
axes = np.array([2, 4, 5]).astype(np.int64)
node = onnx.helper.make_node(
'Unsqueeze',
inputs=['x', 'axes'],
outputs=['y'],
)
y = np.expand_dims(x, axis=2)
y = np.expand_dims(y, axis=4)
y = np.expand_dims(y, axis=5)
expect(node, inputs=[x, axes], outputs=[y],
name='test_unsqueeze_three_axes')
unsqueeze_unsorted_axes
x = np.random.randn(3, 4, 5).astype(np.float32)
axes = np.array([5, 4, 2]).astype(np.int64)
node = onnx.helper.make_node(
'Unsqueeze',
inputs=['x', 'axes'],
outputs=['y'],
)
y = np.expand_dims(x, axis=2)
y = np.expand_dims(y, axis=4)
y = np.expand_dims(y, axis=5)
expect(node, inputs=[x, axes], outputs=[y],
name='test_unsqueeze_unsorted_axes')
unsqueeze_negative_axes
node = onnx.helper.make_node(
'Unsqueeze',
inputs=['x', 'axes'],
outputs=['y'],
)
x = np.random.randn(1, 3, 1, 5).astype(np.float32)
axes = np.array([-2]).astype(np.int64)
y = np.expand_dims(x, axis=-2)
expect(node, inputs=[x, axes], outputs=[y],
name='test_unsqueeze_negative_axes')
Differences
0 | 0 | Insert single-dimensional entries to the shape of an input tensor (data). | Insert single-dimensional entries to the shape of an input tensor (data). |
1 | 1 | Takes one required argument axes - which contains a list of dimension indices and this operator will insert a dimension of value 1 into the corresponding index of the output tensor (expanded). |
|
2 | 2 |
|
|
3 | 3 | For example: | For example: |
4 | 4 | Given an input tensor (data) of shape [3, 4, 5], then | Given an input tensor (data) of shape [3, 4, 5], then |
5 | 5 | Unsqueeze(data, axes=[0, 4]) outputs a tensor (expanded) containing same data as data but with shape [1, 3, 4, 5, 1]. | Unsqueeze(data, axes=[0, 4]) outputs a tensor (expanded) containing same data as data but with shape [1, 3, 4, 5, 1]. |
6 | 6 |
|
|
7 | 7 | The attribute axes should not contain any duplicate entries. It is an error if it contains duplicates. |
|
8 | 8 | The rank of the output tensor (output_rank) is the rank of the input tensor (data) plus the number of values in axes. | The rank of the output tensor (output_rank) is the rank of the input tensor (data) plus the number of values in axes. |
9 | 9 | Each value in axes should be within the (inclusive) range [-output_rank , output_rank - 1]. | Each value in axes should be within the (inclusive) range [-output_rank , output_rank - 1]. |
10 | 10 | The order of values in axes does not matter and can come in any order. | The order of values in axes does not matter and can come in any order. |
11 | 11 |
|
|
12 | **Inputs** | ||
13 |
| ||
12 | 14 | **Attributes** |
|
13 |
| ||
15 | Original tensor | ||
14 | 16 | * **axes** (required): |
|
15 | 17 | List of integers indicating the dimensions to be inserted. Negative | List of integers indicating the dimensions to be inserted. Negative |
16 | 18 | value means counting dimensions from the back. Accepted range is | value means counting dimensions from the back. Accepted range is |
17 | 19 | [-r, r-1] where r = rank(expanded). | [-r, r-1] where r = rank(expanded). |
18 | 20 |
|
|
19 | **Inputs** | ||
20 |
| ||
21 | * **data** (heterogeneous) - **T**: | ||
22 | Original tensor | ||
23 |
| ||
24 | 21 | **Outputs** | **Outputs** |
25 | 22 |
|
|
26 | 23 | * **expanded** (heterogeneous) - **T**: | * **expanded** (heterogeneous) - **T**: |
27 | 24 | Reshaped tensor with same data as input. | Reshaped tensor with same data as input. |
28 | 25 |
|
|
29 | 26 | **Type Constraints** | **Type Constraints** |
30 | 27 |
|
|
31 | 28 | * **T** in ( | * **T** in ( |
29 | tensor(bfloat16), | ||
32 | 30 | tensor(bool), | tensor(bool), |
33 | 31 | tensor(complex128), | tensor(complex128), |
34 | 32 | tensor(complex64), | tensor(complex64), |
35 | 33 | tensor(double), | tensor(double), |
36 | 34 | tensor(float), | tensor(float), |
37 | 35 | tensor(float16), | tensor(float16), |
38 | 36 | tensor(int16), | tensor(int16), |
39 | 37 | tensor(int32), | tensor(int32), |
40 | 38 | tensor(int64), | tensor(int64), |
41 | 39 | tensor(int8), | tensor(int8), |
42 | 40 | tensor(string), | tensor(string), |
43 | 41 | tensor(uint16), | tensor(uint16), |
44 | 42 | tensor(uint32), | tensor(uint32), |
45 | 43 | tensor(uint64), | tensor(uint64), |
46 | 44 | tensor(uint8) | tensor(uint8) |
47 | 45 | ): | ): |
48 | 46 | Constrain input and output types to all tensor types. | Constrain input and output types to all tensor types. |
Unsqueeze - 11#
Version
name: Unsqueeze (GitHub)
domain: main
since_version: 11
function: False
support_level: SupportType.COMMON
shape inference: True
This version of the operator has been available since version 11.
Summary
Insert single-dimensional entries to the shape of an input tensor (data). Takes one required argument axes - which contains a list of dimension indices and this operator will insert a dimension of value 1 into the corresponding index of the output tensor (expanded).
- For example:
Given an input tensor (data) of shape [3, 4, 5], then Unsqueeze(data, axes=[0, 4]) outputs a tensor (expanded) containing same data as data but with shape [1, 3, 4, 5, 1].
The attribute axes should not contain any duplicate entries. It is an error if it contains duplicates. The rank of the output tensor (output_rank) is the rank of the input tensor (data) plus the number of values in axes. Each value in axes should be within the (inclusive) range [-output_rank , output_rank - 1]. The order of values in axes does not matter and can come in any order.
Attributes
axes (required): List of integers indicating the dimensions to be inserted. Negative value means counting dimensions from the back. Accepted range is [-r, r-1] where r = rank(expanded).
Inputs
data (heterogeneous) - T: Original tensor
Outputs
expanded (heterogeneous) - T: Reshaped tensor with same data as input.
Type Constraints
T in ( tensor(bool), tensor(complex128), tensor(complex64), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8) ): Constrain input and output types to all tensor types.
Differences
0 | 0 | Insert single-dimensional entries to the shape of a tensor. |
|
1 | 1 | Takes one required argument axes, a list of dimensions that will be inserted. |
|
2 |
| ||
2 | 3 | Dimension indices in axes are as seen in the output tensor. For example: |
|
3 | 4 | Given a tensor such that tensor with shape [3, 4, 5], then |
|
5 | Unsqueeze(data, axes=[0, 4]) outputs a tensor (expanded) containing same data as data but with shape [1, 3, 4, 5, 1]. | ||
6 |
| ||
7 | The attribute axes should not contain any duplicate entries. It is an error if it contains duplicates. | ||
4 | 8 | Unsqueeze(tensor, axes=[0, 4]) has shape [1, 3, 4, 5, 1] |
|
9 | Each value in axes should be within the (inclusive) range [-output_rank , output_rank - 1]. | ||
10 | The order of values in axes does not matter and can come in any order. | ||
5 | 11 |
|
|
6 | 12 | **Attributes** | **Attributes** |
7 | 13 |
|
|
8 | 14 | * **axes** (required): | * **axes** (required): |
9 | 15 | List of non-negative integers, indicate the dimensions to be |
|
10 | inserted | ||
16 | value means counting dimensions from the back. Accepted range is | ||
17 | [-r, r-1] where r = rank(expanded). | ||
11 | 18 |
|
|
12 | 19 | **Inputs** | **Inputs** |
13 | 20 |
|
|
14 | 21 | * **data** (heterogeneous) - **T**: | * **data** (heterogeneous) - **T**: |
15 | 22 | Original tensor | Original tensor |
16 | 23 |
|
|
17 | 24 | **Outputs** | **Outputs** |
18 | 25 |
|
|
19 | 26 | * **expanded** (heterogeneous) - **T**: | * **expanded** (heterogeneous) - **T**: |
20 | 27 | Reshaped tensor with same data as input. | Reshaped tensor with same data as input. |
21 | 28 |
|
|
22 | 29 | **Type Constraints** | **Type Constraints** |
23 | 30 |
|
|
24 | 31 | * **T** in ( | * **T** in ( |
25 | 32 | tensor(bool), | tensor(bool), |
26 | 33 | tensor(complex128), | tensor(complex128), |
27 | 34 | tensor(complex64), | tensor(complex64), |
28 | 35 | tensor(double), | tensor(double), |
29 | 36 | tensor(float), | tensor(float), |
30 | 37 | tensor(float16), | tensor(float16), |
31 | 38 | tensor(int16), | tensor(int16), |
32 | 39 | tensor(int32), | tensor(int32), |
33 | 40 | tensor(int64), | tensor(int64), |
34 | 41 | tensor(int8), | tensor(int8), |
35 | 42 | tensor(string), | tensor(string), |
36 | 43 | tensor(uint16), | tensor(uint16), |
37 | 44 | tensor(uint32), | tensor(uint32), |
38 | 45 | tensor(uint64), | tensor(uint64), |
39 | 46 | tensor(uint8) | tensor(uint8) |
40 | 47 | ): | ): |
41 | 48 | Constrain input and output types to all tensor types. | Constrain input and output types to all tensor types. |
Unsqueeze - 1#
Version
name: Unsqueeze (GitHub)
domain: main
since_version: 1
function: False
support_level: SupportType.COMMON
shape inference: True
This version of the operator has been available since version 1.
Summary
Insert single-dimensional entries to the shape of a tensor. Takes one required argument axes, a list of dimensions that will be inserted. Dimension indices in axes are as seen in the output tensor. For example:
Given a tensor such that tensor with shape [3, 4, 5], then Unsqueeze(tensor, axes=[0, 4]) has shape [1, 3, 4, 5, 1]
Attributes
axes (required): List of non-negative integers, indicate the dimensions to be inserted
Inputs
data (heterogeneous) - T: Original tensor
Outputs
expanded (heterogeneous) - T: Reshaped tensor with same data as input.
Type Constraints
T in ( tensor(bool), tensor(complex128), tensor(complex64), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8) ): Constrain input and output types to all tensor types.