webmachinelearning / webnn-native

🧠⚙️ Standalone native implementation of the Web Neural Network API
Apache License 2.0
50 stars 21 forks source link

[OV] Fail to build deeplab model with NHWC + OpenVino backend #54

Open Honry opened 3 years ago

Honry commented 3 years ago

Test case: https://github.com/webmachinelearning/webnn-native/pull/52

When test DeepLab sample with NHWC layout and OpenVino backend (Node.js Electron app), we failed to build the graph at resample op at following code line:

    const resample0 = this.builder_.resample(
        conv4, {sizes: [1, 65, 65, 256], mode: 'linear'});

https://github.com/webmachinelearning/webnn-samples/blob/master/semantic_segmentation/deeplabv3_mnv2_nhwc.js#L137.

While this works on DML backend, and NCHW layout also works on OpenVino backend.

Error Log:

Error: Failed to build graph.
    at DeepLabV3MNV2Nhwc.build (deeplabv3_mnv2_nhwc.js:151)
    at main (main.js:334)
    at async window.onload (index.html?undefined:205)
huningxin commented 3 years ago

The root cause should be the OpenVINO backend doesn't support resample 4D tensor in NHWC layout.

This could be reproduced by following test case:

TEST_F(ResampleTests, UpsampleLinearNhwc) {
    const std::vector<int32_t> inputShape = {1, 2, 2, 1};
    const std::vector<float> inputData = {1, 2, 3, 4};
    const std::vector<int32_t> expectedShape = {1, 4, 4, 1};
    const std::vector<float> expectedValue = {
        1., 1.25, 1.75, 2., 1.5, 1.75, 2.25, 2.5, 2.5, 2.75, 3.25, 3.5, 3., 3.25, 3.75, 4.,
    };

    ml::ResampleOptions options;
    options.mode = ml::InterpolationMode::Linear;
    std::vector<float> scales = {1.0, 1.0, 2.0, 2.0};
    options.scalesCount = scales.size();
    options.scales = scales.data();
    TestResample(inputShape, inputData, expectedShape, expectedValue, &options);

    options = {};
    options.mode = ml::InterpolationMode::Linear;
    std::vector<int32_t> sizes = {1, 1, 4, 4};
    options.sizesCount = sizes.size();
    options.sizes = sizes.data();
    TestResample(inputShape, inputData, expectedShape, expectedValue, &options);
}
huningxin commented 3 years ago

@fujunwei , could you please send a PR based your solution? Thanks.