microsoft / onnxruntime

ONNX Runtime: cross-platform, high performance ML inferencing and training accelerator
https://onnxruntime.ai
MIT License
14.51k stars 2.9k forks source link

[Web] How should I get wasm file? #19829

Open Iven10252158 opened 7 months ago

Iven10252158 commented 7 months ago

Describe the issue

I use vue3+vite and load onnxruntime-web plugin. I meet some error. I get wasm file failed.

I wondering to know how should i get wasm file? @fs-eire 截圖 2024-03-08 下午4 03 29

My Vue3+Vite Version: vue:"^3.4.15", vite: "~3.0.4", onnxruntime-web: "^1.17.1", vite-plugin-static-copy: "^1.0.1",

In my vite.config.ts import { viteStaticCopy } from 'vite-plugin-static-copy'

export default ({ mode }) => { process.env = { ...process.env, ...loadEnv(mode, process.cwd()) } return defineConfig({ base: process.env.VITE_APP_BASE_URL, plugins: [ vue(), viteStaticCopy({ targets: [ { src: "./node_modules/onnxruntime-web/dist/*.wasm", dest: "./", }, ], }), removeConsole(), }), ], css: {postcss}, resolve: { alias: { '@': path.resolve(__dirname, 'src') } }, }

To reproduce

In My Vue app import * as ort from 'onnxruntime-web'; const modelDir = 'https://mode-marie-ai-2023.s3.ap-northeast-1.amazonaws.com/inspiration_generator/onnx/sam_onnx_quantized_vit_h.onnx' onMounted(async () => { console.log('onMounted') try { if (modelDir === undefined) return const modelUrl:string = modelDir const aaa = await ort.InferenceSession.create(modelUrl) console.log('completed') } catch (error) { console.log(error) } })

Urgency

urgent!

ONNX Runtime Installation

Released Package

ONNX Runtime Version or Commit ID

1.17.1

Execution Provider

Other / Unknown

fs-eire commented 7 months ago

you may need to figure out what is the actual path of .wasm files are served.

If the browser log, it tries to get the files at https://localhost:5173/admin/ort-wasm-simd.wasm, and this URL is not valid.

In your config, I see you copy the files to "./". Not sure how this will map to the actual deploy path. You need to figure out this.

Since your script tries to get the .wasm files from path "https://localhost:5173/admin/", I assume your bundle.js is in the same path. You may either figure out how to deploy the .wasm files to the same path, or use ort.env.wasm.wasmPaths to override the wasm paths if you know where it is.

github-actions[bot] commented 6 months ago

This issue has been automatically marked as stale due to inactivity and will be closed in 30 days if no further activity occurs. If further support is needed, please provide an update and/or more details.

Mirror-Yu commented 5 months ago

I also encountered this problem, using the onnx model, but reporting an error that wasm could not find,Have you solved it yet?