mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-05-23 22:13:38 +00:00
[WebNN EP] Fix bug of padding in Op ConvTranspose (#18577)
Get the dimensions of H and W according to the layout.
This commit is contained in:
parent
b1e749e3be
commit
4025bd8ebd
1 changed files with 12 additions and 2 deletions
|
|
@ -251,8 +251,18 @@ Status ConvOpBuilder::AddToModelBuilderImpl(ModelBuilder& model_builder, const N
|
|||
std::vector<int64_t> input_shape;
|
||||
ORT_RETURN_IF_NOT(GetShape(*input_defs[0], input_shape, logger), "Cannot get shape");
|
||||
for (size_t i = 0; i < 2; i++) {
|
||||
total_padding[i] = strides[i] * (narrow<size_t>(input_shape[i + 1]) - 1) +
|
||||
output_padding[i] + ((kernel_shape[i] - 1) * dilations[i] + 1) - output_shape[i];
|
||||
// Get the dimensions of H and W.
|
||||
// For NHWC layout, the dimensions of H and W correspond to index 1 and 2.
|
||||
// For NCHW layout, the dimensions of H and W correspond to index 2 and 3.
|
||||
if (model_builder.GetPreferredLayout() == DataLayout::NHWC) {
|
||||
total_padding[i] = strides[i] * (narrow<size_t>(input_shape[i + 1]) - 1) +
|
||||
output_padding[i] + ((kernel_shape[i] - 1) * dilations[i] + 1) - output_shape[i];
|
||||
} else {
|
||||
ORT_RETURN_IF_NOT(model_builder.GetPreferredLayout() == DataLayout::NCHW,
|
||||
"WebNN GPU backend preferred layout should be NCHW.");
|
||||
total_padding[i] = strides[i] * (narrow<size_t>(input_shape[i + 2]) - 1) +
|
||||
output_padding[i] + ((kernel_shape[i] - 1) * dilations[i] + 1) - output_shape[i];
|
||||
}
|
||||
}
|
||||
pads[0] = total_padding[0] - (total_padding[0] / 2);
|
||||
pads[1] = total_padding[0] / 2;
|
||||
|
|
|
|||
Loading…
Reference in a new issue