Merge pull request #22639 from WanliZhong:issue#22625
DNN: Make Unsqueeze layer support negative axes
This commit is contained in:
commit
1c5dcbcac8
@ -2313,8 +2313,9 @@ void ONNXImporter::parseUnsqueeze(LayerParams& layerParams, const opencv_onnx::N
|
|||||||
}
|
}
|
||||||
// CV_Assert(axes.getIntValue(axes.size()-1) <= dims.size());
|
// CV_Assert(axes.getIntValue(axes.size()-1) <= dims.size());
|
||||||
for (int j = 0; j < axes.size(); j++) {
|
for (int j = 0; j < axes.size(); j++) {
|
||||||
const int idx = axes.getIntValue(j);
|
int idx = axes.getIntValue(j);
|
||||||
CV_Assert(idx <= dims.size());
|
idx = idx < 0 ? idx + input_dims + 1 : idx;
|
||||||
|
CV_Assert(0 <= idx && idx <= dims.size());
|
||||||
dims.insert(dims.begin() + idx, 1);
|
dims.insert(dims.begin() + idx, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2331,6 +2332,7 @@ void ONNXImporter::parseUnsqueeze(LayerParams& layerParams, const opencv_onnx::N
|
|||||||
|
|
||||||
MatShape inpShape = outShapes[node_proto.input(0)];
|
MatShape inpShape = outShapes[node_proto.input(0)];
|
||||||
int axis = axes.getIntValue(0);
|
int axis = axes.getIntValue(0);
|
||||||
|
axis = axis < 0 ? axis + (int)inpShape.size() + 1 : axis;
|
||||||
CV_Assert(0 <= axis && axis <= inpShape.size());
|
CV_Assert(0 <= axis && axis <= inpShape.size());
|
||||||
std::vector<int> outShape = inpShape;
|
std::vector<int> outShape = inpShape;
|
||||||
outShape.insert(outShape.begin() + axis, 1);
|
outShape.insert(outShape.begin() + axis, 1);
|
||||||
|
|||||||
@ -1096,6 +1096,11 @@ TEST_P(Test_ONNX_layers, Reshape)
|
|||||||
testONNXModels("unsqueeze_opset_13");
|
testONNXModels("unsqueeze_opset_13");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_P(Test_ONNX_layers, Unsqueeze_Neg_Axes)
|
||||||
|
{
|
||||||
|
testONNXModels("unsqueeze_neg_axes");
|
||||||
|
}
|
||||||
|
|
||||||
TEST_P(Test_ONNX_layers, Squeeze)
|
TEST_P(Test_ONNX_layers, Squeeze)
|
||||||
{
|
{
|
||||||
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_MYRIAD)
|
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_MYRIAD)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user