From 7d0cfb6e5b966fabd9c778e14a82ec6f4e827453 Mon Sep 17 00:00:00 2001 From: Radionic Date: Wed, 3 Jan 2024 12:14:48 +0800 Subject: [PATCH] fix: onnx model loading --- js/onnx.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/js/onnx.js b/js/onnx.js index b0ecf57..fc06fa0 100644 --- a/js/onnx.js +++ b/js/onnx.js @@ -6,11 +6,13 @@ import { modelData, onnxMaskToImage } from "./onnx_helper.js"; ort.env.wasm.wasmPaths = "https://cdn.jsdelivr.net/npm/onnxruntime-web/dist/"; export let model = null; +let modelType = null; // Initialize the ONNX model -export const initModel = async (modelType) => { +export const initModel = async (type) => { try { - if (!model) { + if (!model || modelType !== type) { + modelType = type; model = await ort.InferenceSession.create( `${location.protocol}//${location.host}/sam_model?type=${modelType}` );