Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Web] ONNX Runtime Initialization Fails with irVersion Error #22931

Open
lstrhsu opened this issue Nov 23, 2024 · 0 comments
Open

[Web] ONNX Runtime Initialization Fails with irVersion Error #22931

lstrhsu opened this issue Nov 23, 2024 · 0 comments
Labels
.NET Pull requests that update .net code platform:web issues related to ONNX Runtime web; typically submitted using template

Comments

@lstrhsu
Copy link

lstrhsu commented Nov 23, 2024

Describe the issue

I am encountering an issue with the ONNX Runtime initialization in my userscript. The error message indicates that the irVersion property is being accessed on a null object, which suggests that the ONNX model is not being loaded correctly. Additionally, the ONNX Runtime version is showing as undefined, which implies that the onnxruntime-web library might not be properly initialized or loaded.

To reproduce

Load the userscript in a browser environment

  • Chrome 133.0.6847.2
  • Tampermonkey v5.3.2

Observe the console logs for the following error

ONNX Runtime initialization failed: TypeError: Cannot read properties of null (reading 'irVersion')
Error stack: TypeError: Cannot read properties of null (reading 'irVersion')
Initialization failed: Error: ONNX initialization failed
Error stack: Error: ONNX initialization failed

Console Logs

Script execution started...
Starting initialization...
Initializing ONNX...
ort: object
ONNX Runtime version: undefined
Fetching model from:[my model](https://raw.githubusercontent.com/lstrhsu/MyHost/main/model.onnx)
Fetching model...
Model data size: 1153332 bytes
Creating ONNX Runtime session...
ONNX Runtime initialization failed: TypeError: Cannot read properties of null (reading ['irVersion')]

Related Userscript code

// @require      https://cdn.jsdelivr.net/npm/[email protected]/dist/ort.min.js
// @connect      raw.githubusercontent.com
// @connect      cdn.jsdelivr.net
// @grant        GM_xmlhttpRequest
// @grant        unsafeWindow
// @connect      microsoft.github.io
// @resource     WASM_SIMD https://cdn.jsdelivr.net/npm/[email protected]/dist/ort-wasm-simd.wasm
// @resource     WASM https://cdn.jsdelivr.net/npm/[email protected]/dist/ort-wasm.wasm
// ==/UserScript==
(async function() {
    'use strict';
    
    console.log('Script execution started...');

    // Initialize ONNX session
    let session;

    // Configure ONNX Runtime
    const initONNX = async () => {
        try {
            // Check if ONNX Runtime is loaded correctly
            console.log('ort:', typeof ort);
            if (typeof ort === 'undefined') {
                throw new Error('ONNX Runtime not loaded');
            }
            console.log('ONNX Runtime version:', ort.version);

            // Configuration options
            const options = {
                executionProviders: ['webgl'], // Use WebGL backend
                graphOptimizationLevel: 'all'
            };

            // Use the correct model URL
            const MODEL_URL = 'https://raw.githubusercontent.com/lstrhsu/MyHost/main/model.onnx';
            console.log('Fetching model from:', MODEL_URL);

            // Fetch model data
            console.log('Fetching model...');
            const modelResponse = await new Promise((resolve, reject) => {
                GM_xmlhttpRequest({
                    method: 'GET',
                    url: MODEL_URL,
                    responseType: 'arraybuffer',
                    onload: (response) => {
                        // Validate response
                        if (response.status !== 200) {
                            reject(new Error(`Model download failed: ${response.status}`));
                            return;
                        }
                        resolve(response);
                    },
                    onerror: reject
                });
            });

            // Use ArrayBuffer directly
            const modelBuffer = modelResponse.response;
            console.log('Model data size:', modelBuffer.byteLength, 'bytes');

            // Check if model data is valid
            if (!modelBuffer || modelBuffer.byteLength === 0) {
                throw new Error('Model data is invalid or empty');
            }

            // Create session
            console.log('Creating ONNX Runtime session...');
            session = await ort.InferenceSession.create(modelBuffer, options);
            
            // Validate session
            console.log('Session created successfully');
            console.log('Input nodes:', session.inputNames);
            console.log('Output nodes:', session.outputNames);

            return true;
        } catch (error) {
            console.error('ONNX Runtime initialization failed:', error);
            console.error('Error stack:', error.stack);
            return false;
        }
    };

Model Composition

Environment Information:

  • ONNX Version: 1.13.1
  • ONNX Runtime Version: 1.13.1

Version Compatibility Check:

  • Model Opset Version: 13
  • Maximum Supported Opset Version in Current Environment: 17
  • Compatibility: ✓ Compatible

Model Validation: Passed ✓

  • Warnings: The following operators may need updates: Squeeze & Reshape

Web Deployment Compatibility Check (ONNX.js):

  • IR Version 7: ✓ Compatible
  • Opset Version 13: ✓ Compatible

Metadata Information:

  • ONNX IR Version: 7
  • Producer Name: tf2onnx
  • Producer Version: 1.13.0 2c1db5
  • Model Version: 0
  • Opset Versions: [13, 2]

Urgency

This issue is urgent because it blocks a critical feature in our application that relies on ONNX Runtime for real-time captcha solving. We have a project deadline approaching in two weeks, and resolving this issue is crucial for our deployment schedule.

ONNX Runtime Installation

Built from Source

ONNX Runtime Version or Commit ID

Version: 1.13.1

Execution Provider

'webgl' (WebGL)

@lstrhsu lstrhsu added the platform:web issues related to ONNX Runtime web; typically submitted using template label Nov 23, 2024
@github-actions github-actions bot added the .NET Pull requests that update .net code label Nov 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
.NET Pull requests that update .net code platform:web issues related to ONNX Runtime web; typically submitted using template
Projects
None yet
Development

No branches or pull requests

1 participant