You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Insert single-dimensional entries to the shape of a tensor.
13807
-
Takes one required argument `axes`, a list of dimensions that will be inserted.
13808
-
Dimension indices in `axes` are as seen in the output tensor. For example:
13809
-
Given a tensor such that tensor with shape [3, 4, 5], then
13810
-
Unsqueeze(tensor, axes=[0, 4]) has shape [1, 3, 4, 5, 1]
13806
+
Insert single-dimensional entries to the shape of an input tensor (`data`).
13807
+
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`).
13808
+
13809
+
For example:
13810
+
Given an input tensor (`data`) of shape [3, 4, 5], then
13811
+
Unsqueeze(data, axes=[0, 4]) outputs a tensor (`expanded`) containing same data as `data` but with shape [1, 3, 4, 5, 1].
13812
+
13813
+
The attribute `axes` should not contain any duplicate entries. It is an error if it contains duplicates.
13814
+
The rank of the output tensor (`output_rank`) is the rank of the input tensor (`data`) plus the number of values in `axes`.
13815
+
Each value in `axes` should be within the (inclusive) range [-output_rank , output_rank - 1].
13816
+
The order of values in `axes` does not matter and can come in any order.
13817
+
13811
13818
13812
13819
#### Version
13813
13820
@@ -13817,7 +13824,7 @@ This version of the operator has been available since version 11 of the default
13817
13824
13818
13825
<dl>
13819
13826
<dt><tt>axes</tt> : list of ints (required)</dt>
13820
-
<dd>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(data).</dd>
13827
+
<dd>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).</dd>
Insert single-dimensional entries to the shape of a tensor.
18534
-
Takes one required argument `axes`, a list of dimensions that will be inserted.
18535
-
Dimension indices in `axes` are as seen in the output tensor. For example:
18536
-
Given a tensor such that tensor with shape [3, 4, 5], then
18537
-
Unsqueeze(tensor, axes=[0, 4]) has shape [1, 3, 4, 5, 1]
18533
+
Insert single-dimensional entries to the shape of an input tensor (`data`).
18534
+
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`).
18535
+
18536
+
For example:
18537
+
Given an input tensor (`data`) of shape [3, 4, 5], then
18538
+
Unsqueeze(data, axes=[0, 4]) outputs a tensor (`expanded`) containing same data as `data` but with shape [1, 3, 4, 5, 1].
18539
+
18540
+
The attribute `axes` should not contain any duplicate entries. It is an error if it contains duplicates.
18541
+
The rank of the output tensor (`output_rank`) is the rank of the input tensor (`data`) plus the number of values in `axes`.
18542
+
Each value in `axes` should be within the (inclusive) range [-output_rank , output_rank - 1].
18543
+
The order of values in `axes` does not matter and can come in any order.
18544
+
18538
18545
18539
18546
#### Version
18540
18547
@@ -18546,7 +18553,7 @@ Other versions of this operator: <a href="Changelog.md#Unsqueeze-1">Unsqueeze-1<
18546
18553
18547
18554
<dl>
18548
18555
<dt><tt>axes</tt> : list of ints (required)</dt>
18549
-
<dd>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(data).</dd>
18556
+
<dd>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).</dd>
Copy file name to clipboardExpand all lines: onnx/defs/tensor/defs.cc
+35-9Lines changed: 35 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -1301,11 +1301,18 @@ ONNX_OPERATOR_SET_SCHEMA(
1301
1301
}));
1302
1302
1303
1303
staticconstchar* Unsqueeze_ver11_doc = R"DOC(
1304
-
Insert single-dimensional entries to the shape of a tensor.
1305
-
Takes one required argument `axes`, a list of dimensions that will be inserted.
1306
-
Dimension indices in `axes` are as seen in the output tensor. For example:
1307
-
Given a tensor such that tensor with shape [3, 4, 5], then
1308
-
Unsqueeze(tensor, axes=[0, 4]) has shape [1, 3, 4, 5, 1]
1304
+
Insert single-dimensional entries to the shape of an input tensor (`data`).
1305
+
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`).
1306
+
1307
+
For example:
1308
+
Given an input tensor (`data`) of shape [3, 4, 5], then
1309
+
Unsqueeze(data, axes=[0, 4]) outputs a tensor (`expanded`) containing same data as `data` but with shape [1, 3, 4, 5, 1].
1310
+
1311
+
The attribute `axes` should not contain any duplicate entries. It is an error if it contains duplicates.
1312
+
The rank of the output tensor (`output_rank`) is the rank of the input tensor (`data`) plus the number of values in `axes`.
1313
+
Each value in `axes` should be within the (inclusive) range [-output_rank , output_rank - 1].
1314
+
The order of values in `axes` does not matter and can come in any order.
1315
+
1309
1316
)DOC";
1310
1317
1311
1318
ONNX_OPERATOR_SET_SCHEMA(
@@ -1315,7 +1322,7 @@ ONNX_OPERATOR_SET_SCHEMA(
1315
1322
.Attr(
1316
1323
"axes",
1317
1324
"List of integers indicating the dimensions to be inserted. Negative value means counting dimensions "
1318
-
"from the back. Accepted range is [-r, r-1] where r = rank(data).",
1325
+
"from the back. Accepted range is [-r, r-1] where r = rank(expanded).",
1319
1326
AttributeProto::INTS)
1320
1327
.SetDoc(Unsqueeze_ver11_doc)
1321
1328
.Input(0, "data", "Original tensor", "T")
@@ -1334,7 +1341,16 @@ ONNX_OPERATOR_SET_SCHEMA(
1334
1341
if (!getRepeatedAttribute(ctx, "axes", axes)) {
1335
1342
return;
1336
1343
}
1337
-
std::sort(axes.begin(), axes.end());
1344
+
1345
+
// validate 'axes' for duplicate entries
1346
+
std::unordered_set<int64_t> unique_values;
1347
+
for (constauto val : axes) {
1348
+
if (unique_values.find(val) != unique_values.end()) {
1349
+
fail_shape_inference(
1350
+
"'axes' attribute must not contain any duplicates");
1351
+
}
1352
+
unique_values.insert(val);
1353
+
}
1338
1354
1339
1355
if (!ctx.getInputType(0)->tensor_type().has_shape()) {
0 commit comments