Class Environment
java.lang.Object
smile.onnx.Environment
- All Implemented Interfaces:
AutoCloseable
A wrapper around the ONNX Runtime
OrtEnv object. The environment
manages thread pools and logging configuration that are shared across all
sessions created from the same environment.
For most use cases the convenience factory methods on
InferenceSession (which create their own private environment) are
sufficient. Use this class when you want to share one environment — and
therefore its thread pools — across several sessions.
try (var env = new Environment(LoggingLevel.WARNING, "my-app")) {
try (var opts = new SessionOptions()) {
var session = env.createSession("model.onnx", opts);
// ...
}
}
-
Constructor Summary
ConstructorsConstructorDescriptionEnvironment(LoggingLevel loggingLevel, String logId) Creates anEnvironmentwith the given logging level and log identifier. -
Method Summary
Modifier and TypeMethodDescriptionReturns the list of available execution provider names on this machine/installation (e.g.static StringReturns the ONNX Runtime build information string (e.g.voidclose()createSession(byte[] modelBytes) Creates anInferenceSessionfrom an in-memory model that shares this environment, using default session options.createSession(byte[] modelBytes, SessionOptions sessionOptions) Creates anInferenceSessionfrom an in-memory model that shares this environment.createSession(String modelPath) Creates anInferenceSessionthat shares this environment using default session options.createSession(String modelPath, SessionOptions sessionOptions) Creates anInferenceSessionthat shares this environment.voidsetLoggingLevel(LoggingLevel level) Updates the minimum logging level of this environment.
-
Constructor Details
-
Environment
public Environment() -
Environment
Creates anEnvironmentwith the given logging level and log identifier.- Parameters:
loggingLevel- minimum severity for log messages.logId- short string identifying this environment in logs.
-
-
Method Details
-
buildInfo
Returns the ONNX Runtime build information string (e.g. version and commit hash).- Returns:
- build info string.
-
availableProviders
-
setLoggingLevel
Updates the minimum logging level of this environment.- Parameters:
level- new minimum logging level.
-
createSession
Creates anInferenceSessionthat shares this environment using default session options.- Parameters:
modelPath- path to the.onnxmodel file.- Returns:
- the loaded session.
-
createSession
Creates anInferenceSessionfrom an in-memory model that shares this environment, using default session options.- Parameters:
modelBytes- the serialized ONNX model bytes.- Returns:
- the loaded session.
-
createSession
Creates anInferenceSessionthat shares this environment.- Parameters:
modelPath- path to the.onnxmodel file.sessionOptions- session configuration.- Returns:
- the loaded session.
-
createSession
Creates anInferenceSessionfrom an in-memory model that shares this environment.- Parameters:
modelBytes- the serialized ONNX model bytes.sessionOptions- session configuration.- Returns:
- the loaded session.
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-