onnxruntime
onnxruntime copied to clipboard
[Web] Failed to compile shader on WebGL
Describe the issue
My model converted from tensorflow to onnx. It run on wasm successfully, but fail on WebGL.
Error log:
ortCreate.ts:42 Error: Failed to compile shader: ERROR: 0:37: 'X' : undeclared identifier
ERROR: 0:37: 'texture' : no matching overloaded function found
ERROR: 0:37: '=' : dimension mismatch
ERROR: 0:37: '=' : cannot convert from 'const mediump float' to 'highp 4-component vector of float'
Shader source:
#version 300 es
precision highp float;
precision highp int;
precision highp sampler2D;
in vec2 TexCoords;
out vec4 outputColor;
const vec2 halfCR = vec2(0.5, 0.5);
// Custom vector types to handle higher dimenalities.
struct ivec5
{
int x;
int y;
int z;
int w;
int u;
};
struct ivec6
{
int x;
int y;
int z;
int w;
int u;
int v;
};
int imod(int x, int y) {
return x - y * (x / y);
}
uniform sampler2D A;
void main() {
vec4 v = texture(X, TexCoords);
outputColor = v;
}
at t.WebGLContext.compileShader (ort-web.min.js:6:341417)
at t.ProgramManager.compile (ort-web.min.js:6:321731)
at ort-web.min.js:6:321119
at t.Profiler.event (ort-web.min.js:6:365352)
at t.ProgramManager.build (ort-web.min.js:6:321053)
at t.WebGLInferenceHandler.executeProgram (ort-web.min.js:6:209696)
at t.WebGLInferenceHandler.run (ort-web.min.js:6:209830)
at t.resize [as impl] (ort-web.min.js:6:281656)
at ort-web.min.js:6:350100
at t.Profiler.event (ort-web.min.js:6:365352)
Could you please help me figure out this issue?
Thank you
To reproduce
code to load model and choose backend
export async function createModelCpu(model: ArrayBuffer): Promise<InferenceSession> {
init();
return await InferenceSession.create(model, {executionProviders: ['wasm']});
}
export async function createModelGpu(model: ArrayBuffer): Promise<InferenceSession> {
init();
return await InferenceSession.create(model, {executionProviders: ['webgl']});
}
Urgency
No response
ONNX Runtime Installation
Released Package
ONNX Runtime Version or Commit ID
1.12.1
Execution Provider
WebGL
This looks like the WebGL shader is generated incorrectly. Could you share more details ( eg. sharing the model ) so that I can try to reproduce the issue?
I get the the same error but with pytorch.
I suspect the F.interpolate function...
class ScaleDown(nn.Module):
def __init__(self, a=1):
super().__init__()
self.a = a
def forward(self, x):
return F.interpolate(x, (x.size(-2)//self.a, x.size(-1)//self.a), mode='area')
class ScaleUp(nn.Module):
def __init__(self, a=1):
super().__init__()
self.a = a
def forward(self, x):
return F.interpolate(x, (x.size(-2)*self.a, x.size(-1)*self.a), mode='nearest')
Here is my onnx file https://drive.google.com/file/d/1mBZjxBCBNATeqvaE9BWpOC32YOysMwd-/view?usp=sharing