Skip to content

[js/web] support 'pytorch_half_pixel' mode for WebGL kernel 'Resize'#11208

Merged
fs-eire merged 5 commits into
microsoft:mainfrom
ncianeo:master
Nov 21, 2022
Merged

[js/web] support 'pytorch_half_pixel' mode for WebGL kernel 'Resize'#11208
fs-eire merged 5 commits into
microsoft:mainfrom
ncianeo:master

Conversation

@ncianeo

@ncianeo ncianeo commented Apr 13, 2022

Copy link
Copy Markdown
Contributor

Description:

  1. add pytorch_half_pixel interpolation mode in resize-packed.ts
    Changes: add the following case in createPackedResizeProgramInfo function:
case 'pytorch_half_pixel':
          getSourceFracIndex = `
                    vec4 getSourceFracIndex(ivec4 coords) {
                        vec4 fcoords = vec4(coords);
                        return vec4(
                            ${outputWidth}.0 > 1.0 ? (fcoords.x + 0.5) / scaleWHWH.x - 0.5 : 0.0,
                            ${outputHeight}.0 > 1.0 ? (fcoords.y + 0.5) / scaleWHWH.y - 0.5 : 0.0,
                            ${outputWidth}.0 > 1.0 ? (fcoords.z + 0.5) / scaleWHWH.z - 0.5 : 0.0,
                            ${outputHeight}.0 > 1.0 ? (fcoords.w + 0.5) / scaleWHWH.w - 0.5 : 0.0
                          );
                    }
                `;
          break;
  1. fix "unrecognized input '' for node: Resize_$num" error when inputs like [input_tensor, None, scale_factor] (roiInput not given) are fed into the resize layer.
    Changes: change in input handling logic in upsample.ts & node scanning logic in graph.ts

Motivation and Context
Before this fix, we aren't able to use webGL backend when the neural network contains pytorch resize layers. This fix adds 'pytorch_half_pixel' interpolation mode support and makes it possible to use webGL backend for more kind of computer vision networks.

This commit solves:
#10430

@ghost

ghost commented Apr 13, 2022

Copy link
Copy Markdown

CLA assistant check
All CLA requirements met.

@fs-eire

fs-eire commented Jun 1, 2022

Copy link
Copy Markdown
Contributor

/azp run ONNX Runtime Web CI Pipeline

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@fs-eire fs-eire changed the title bug fix for "unrecognized input ''" error of Resize operations when u… [js/web] support 'pytorch_half_pixel' mode for WebGL kernel 'Resize' Jun 1, 2022
@fs-eire

fs-eire commented Jun 1, 2022

Copy link
Copy Markdown
Contributor

/azp run ONNX Runtime Web CI Pipeline

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@ytaous

ytaous commented Jul 14, 2022

Copy link
Copy Markdown
Contributor

/azp run Windows CPU CI Pipeline, Windows GPU CI Pipeline, Windows GPU TensorRT CI Pipeline, Windows WebAssembly CI Pipeline, orttraining-amd-gpu-ci-pipeline, orttraining-linux-ci-pipeline, orttraining-linux-gpu-ci-pipeline, orttraining-ortmodule-distributed, onnxruntime-python-checks-ci-pipeline

@ytaous

ytaous commented Jul 14, 2022

Copy link
Copy Markdown
Contributor

/azp run Linux CPU CI Pipeline, Linux CPU Minimal Build E2E CI Pipeline, Linux GPU CI Pipeline, Linux GPU TensorRT CI Pipeline, Linux Nuphar CI Pipeline, Linux OpenVINO CI Pipeline, MacOS CI Pipeline, ONNX Runtime Web CI Pipeline, onnxruntime-binary-size-checks-ci-pipeline

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 8 pipeline(s).

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 9 pipeline(s).

Comment on lines +336 to +339
// handle exception when opset > 9 and roi not given
if (input === '' && nodeProto.input.length === 3 && nodeProto.opType === 'Resize') {
continue;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old ONNX.js graph initialization does not support optional inputs. I will do another change to enable a general support on that.

@fs-eire

fs-eire commented Jul 19, 2022

Copy link
Copy Markdown
Contributor

The CI check "Python format" does not run and seems to block the merge. I tried several ways to trigger it but with no luck... @ncianeo could you do a merge to the latest master branch to trigger the CI to rerun the checks?

@ncianeo

ncianeo commented Jul 20, 2022

Copy link
Copy Markdown
Contributor Author

/azp run ONNX Runtime Web CI Pipeline

@azure-pipelines

Copy link
Copy Markdown
Commenter does not have sufficient privileges for PR 11208 in repo microsoft/onnxruntime

@fs-eire

fs-eire commented Jul 20, 2022

Copy link
Copy Markdown
Contributor

/azp run Windows CPU CI Pipeline, Windows GPU CI Pipeline, Windows GPU TensorRT CI Pipeline, Windows WebAssembly CI Pipeline, orttraining-amd-gpu-ci-pipeline, orttraining-linux-ci-pipeline, orttraining-linux-gpu-ci-pipeline, orttraining-ortmodule-distributed, onnxruntime-python-checks-ci-pipeline

@fs-eire

fs-eire commented Jul 20, 2022

Copy link
Copy Markdown
Contributor

/azp run Linux CPU CI Pipeline, Linux CPU Minimal Build E2E CI Pipeline, Linux GPU CI Pipeline, Linux GPU TensorRT CI Pipeline, Linux Nuphar CI Pipeline, Linux OpenVINO CI Pipeline, MacOS CI Pipeline, ONNX Runtime Web CI Pipeline, onnxruntime-binary-size-checks-ci-pipeline

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 8 pipeline(s).

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 9 pipeline(s).

@sophies927 sophies927 added platform:web issues related to ONNX Runtime web; typically submitted using template and removed component:ort-web labels Aug 12, 2022
@jphdotam

Copy link
Copy Markdown

Hi, is there any progress on getting this in the javascript onnxruntime? It is preventing me from performing webgl based inference on any mainstream segmentation models, and the wasm backend is too slow.

@fs-eire
fs-eire merged commit 307ad14 into microsoft:main Nov 21, 2022
simon-moo pushed a commit to simon-moo/onnxruntime that referenced this pull request Dec 26, 2022
…icrosoft#11208)

**Description**: 
1. add pytorch_half_pixel interpolation mode in resize-packed.ts
Changes: add the following case in createPackedResizeProgramInfo
function:
```
case 'pytorch_half_pixel':
          getSourceFracIndex = `
                    vec4 getSourceFracIndex(ivec4 coords) {
                        vec4 fcoords = vec4(coords);
                        return vec4(
                            ${outputWidth}.0 > 1.0 ? (fcoords.x + 0.5) / scaleWHWH.x - 0.5 : 0.0,
                            ${outputHeight}.0 > 1.0 ? (fcoords.y + 0.5) / scaleWHWH.y - 0.5 : 0.0,
                            ${outputWidth}.0 > 1.0 ? (fcoords.z + 0.5) / scaleWHWH.z - 0.5 : 0.0,
                            ${outputHeight}.0 > 1.0 ? (fcoords.w + 0.5) / scaleWHWH.w - 0.5 : 0.0
                          );
                    }
                `;
          break;
```
2. fix "unrecognized input '' for node: Resize_$num" error when inputs
like [input_tensor, None, scale_factor] (roiInput not given) are fed
into the resize layer.
Changes: change in input handling logic in upsample.ts & node scanning
logic in graph.ts

**Motivation and Context**
Before this fix, we aren't able to use webGL backend when the neural
network contains pytorch resize layers. This fix adds
'pytorch_half_pixel' interpolation mode support and makes it possible to
use webGL backend for more kind of computer vision networks.

This commit solves:
microsoft#10430

Co-authored-by: neo <neo@icode-lab.com>
Co-authored-by: Yulong Wang <7679871+fs-eire@users.noreply.github.com>
siweic0 pushed a commit to siweic0/onnxruntime-web that referenced this pull request May 9, 2024
…icrosoft#11208)

**Description**: 
1. add pytorch_half_pixel interpolation mode in resize-packed.ts
Changes: add the following case in createPackedResizeProgramInfo
function:
```
case 'pytorch_half_pixel':
          getSourceFracIndex = `
                    vec4 getSourceFracIndex(ivec4 coords) {
                        vec4 fcoords = vec4(coords);
                        return vec4(
                            ${outputWidth}.0 > 1.0 ? (fcoords.x + 0.5) / scaleWHWH.x - 0.5 : 0.0,
                            ${outputHeight}.0 > 1.0 ? (fcoords.y + 0.5) / scaleWHWH.y - 0.5 : 0.0,
                            ${outputWidth}.0 > 1.0 ? (fcoords.z + 0.5) / scaleWHWH.z - 0.5 : 0.0,
                            ${outputHeight}.0 > 1.0 ? (fcoords.w + 0.5) / scaleWHWH.w - 0.5 : 0.0
                          );
                    }
                `;
          break;
```
2. fix "unrecognized input '' for node: Resize_$num" error when inputs
like [input_tensor, None, scale_factor] (roiInput not given) are fed
into the resize layer.
Changes: change in input handling logic in upsample.ts & node scanning
logic in graph.ts

**Motivation and Context**
Before this fix, we aren't able to use webGL backend when the neural
network contains pytorch resize layers. This fix adds
'pytorch_half_pixel' interpolation mode support and makes it possible to
use webGL backend for more kind of computer vision networks.

This commit solves:
microsoft#10430

Co-authored-by: neo <neo@icode-lab.com>
Co-authored-by: Yulong Wang <7679871+fs-eire@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

platform:web issues related to ONNX Runtime web; typically submitted using template

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants