-
Notifications
You must be signed in to change notification settings - Fork 1.1k
[v4] suppress console.error while creating InferenceSession #1468
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
Changes from 6 commits
1300ab0
712230d
ffe11a2
9c41c3e
0bf295f
7d7b770
6c0c0c0
dfaf024
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -149,6 +149,21 @@ let webInitChain = Promise.resolve(); | |
| * @returns {Promise<import('onnxruntime-common').InferenceSession & { config: Object}>} The ONNX inference session. | ||
| */ | ||
| export async function createInferenceSession(buffer_or_path, session_options, session_config) { | ||
|
|
||
| /** @type {Array<'verbose' | 'info' | 'warning' | 'error' | 'fatal'>} */ | ||
| const LOG_LEVELS = ['verbose', 'info', 'warning', 'error', 'fatal']; | ||
| /** @type 0|1|2|3|4 */ | ||
| const logSeverityLevel = | ||
| typeof session_options.logSeverityLevel !== 'number' || | ||
| session_options.logSeverityLevel < 0 || | ||
| session_options.logSeverityLevel > 4 | ||
| ? 4 | ||
| : session_options.logSeverityLevel; | ||
|
|
||
| ONNX_WEB.env.logLevel = LOG_LEVELS[logSeverityLevel]; | ||
|
|
||
| session_options = { ...session_options, logSeverityLevel }; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can move the This should hopefully minimize any session_options specific code a user would need to set.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I actually think it makes sense to set the
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, I agree with the point you made about a user not caring what kind of log is 👍 I guess one thing that this solution will prevent is a user modifying the logLevel themselves (which they can do with
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe another option is to set a transformers.js-level logLevel, which would set both env and session-level |
||
|
|
||
| const load = () => InferenceSession.create(buffer_or_path, session_options); | ||
| const session = await (IS_WEB_ENV ? (webInitChain = webInitChain.then(load)) : load()); | ||
| session.config = session_config; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.