Name of the model to use (default: 'u2net')
Optional config: U2NetCustomConfigConfiguration for custom models (required for 'u2net_custom')
Optional options: SessionOptionsSession options for WebNN, WebGPU, and other settings
Promise that resolves to a BaseSession instance
When model name is not supported
When u2net_custom is used without modelPath in config
When model fails to load or initialize
// Create a standard U2Net session
const session = await newSession('u2net');
// Create a session with WebNN acceleration
const session = await newSession('u2net', undefined, {
preferWebNN: true,
webnnDeviceType: 'gpu'
});
// Create a custom model session
const customSession = await newSession('u2net_custom', {
modelPath: '/path/to/my-model.onnx',
inputSize: [512, 512]
});
Create a new session instance with LRU cache management.
Creates a new session for the specified model with intelligent caching. Sessions are cached and reused when possible to improve performance. For custom models, provide the modelPath in the config parameter.