### TrainingInputOutputNames Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go Utilities for getting input and output names for training models. ```APIDOC ## TrainingInputOutputNames ### GetInputOutputNames Retrieves the input and output names for training models given checkpoint and model paths. ### Method `func GetInputOutputNames(checkpointStatePath string, trainingModelPath string, evalModelPath string) (*TrainingInputOutputNames, error)` ### Parameters #### Path Parameters - **checkpointStatePath** (string) - Required - Path to the checkpoint state file. - **trainingModelPath** (string) - Required - Path to the training model file. - **evalModelPath** (string) - Required - Path to the evaluation model file. ``` -------------------------------- ### Get Model Description Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go Use GetDescription to retrieve the model's description string. Returns an error if the description cannot be obtained. ```go func (m *ModelMetadata) GetDescription() (string, error) ``` -------------------------------- ### Get Model Domain Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go Use GetDomain to retrieve the model's domain string. Returns an error if the domain cannot be obtained. ```go func (m *ModelMetadata) GetDomain() (string, error) ``` -------------------------------- ### Get Model Metadata Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go Retrieves metadata for the model associated with the session. ```go func (s *AdvancedSession) GetModelMetadata() (*ModelMetadata, error) ``` -------------------------------- ### Get Model Metadata with Options Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go Use GetModelMetadataWithOptions to retrieve metadata from an ONNX file path, allowing for custom SessionOptions. This is useful for models that require specific configurations to load. ```go func GetModelMetadataWithOptions(path string, opions *SessionOptions) (*ModelMetadata, error) ``` -------------------------------- ### Get Model Metadata from File Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go Use GetModelMetadata to retrieve metadata from an ONNX file path. Ensure InitializeEnvironment() is called first. This function can be computationally expensive as it loads the ONNX content. ```go func GetModelMetadata(path string) (*ModelMetadata, error) ``` -------------------------------- ### Get Model Metadata from ONNX Data Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go Use GetModelMetadataWithONNXData to retrieve metadata directly from a byte slice containing ONNX data. This is an alternative to providing a file path. ```go func GetModelMetadataWithONNXData(data []byte) (*ModelMetadata, error) ``` -------------------------------- ### Get Custom Metadata Map Keys Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go Use GetCustomMetadataMapKeys to retrieve a slice of keys present in the model's custom metadata map. Returns an empty slice or nil if no keys are found. ```go func (m *ModelMetadata) GetCustomMetadataMapKeys() ([]string, error) ``` -------------------------------- ### Run Go Tests Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go Execute the test suite for the repository. Use the benchmark flag to measure performance. ```bash go test -v ``` ```bash go test -v -bench=. ``` -------------------------------- ### Run an ONNX network with AdvancedSession Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go Illustrates loading a network, creating input/output tensors, and executing a session. Requires setting the shared library path before initialization. ```go import ( "fmt" ort "github.com/yalue/onnxruntime_go" "os" ) func main() { // This line _may_ be optional; by default the library will try to load // "onnxruntime.dll" on Windows, and "onnxruntime.so" on any other system. // For stability, programs should always set this explicitly. ort.SetSharedLibraryPath("path/to/onnxruntime.so") err := ort.InitializeEnvironment() if err != nil { panic(err) } defer ort.DestroyEnvironment() // For a slight performance boost and convenience when re-using existing // tensors, this library expects the user to create all input and output // tensors prior to creating the session. If this isn't ideal for your use // case, see the DynamicAdvancedSession type in the documnentation, which // allows input and output tensors to be specified when calling Run() // rather than when initializing a session. inputData := []float32{0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9} inputShape := ort.NewShape(2, 5) inputTensor, err := ort.NewTensor(inputShape, inputData) defer inputTensor.Destroy() // This hypothetical network maps a 2x5 input -> 2x3x4 output. outputShape := ort.NewShape(2, 3, 4) outputTensor, err := ort.NewEmptyTensor[float32](outputShape) defer outputTensor.Destroy() session, err := ort.NewAdvancedSession("path/to/network.onnx", []string{"Input 1 Name"}, []string{"Output 1 Name"}, []ort.Value{inputTensor}, []ort.Value{outputTensor}, nil) defer session.Destroy() // Calling Run() will run the network, reading the current contents of the // input tensors and modifying the contents of the output tensors. err = session.Run() // Get a slice view of the output tensor's data. outputData := outputTensor.GetData() // If you want to run the network on a different input, all you need to do // is modify the input tensor data (available via inputTensor.GetData()) // and call Run() again. // ... } ``` -------------------------------- ### Get Custom Data Tensor Shape Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go Retrieves the shape of the custom tensor. ```go func (t *CustomDataTensor) GetShape() Shape ``` -------------------------------- ### Run DynamicAdvancedSession with Options Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go Executes the session with specified inputs, outputs, and run options. ```go func (s *DynamicAdvancedSession) RunWithOptions(inputs, outputs []Value, opts *RunOptions) error ``` -------------------------------- ### Initialize CUDA Provider Options Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go Use NewCUDAProviderOptions to create a struct for configuring the CUDA backend. Remember to call Destroy() on the returned struct when it's no longer needed. ```go func NewCUDAProviderOptions() (*CUDAProviderOptions, error) ``` -------------------------------- ### Get Custom Data Tensor ONNX Type Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go Returns the ONNX type, which is always ONNXTypeTensor for CustomDataTensor. ```go func (t *CustomDataTensor) GetONNXType() ONNXType ``` -------------------------------- ### Run DynamicAdvancedSession with IoBinding Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go Executes the session using a pre-configured IoBinding instance. The IoBinding must be created from this session. ```go func (s *DynamicAdvancedSession) RunWithBinding(b *IoBinding) error ``` -------------------------------- ### Get Custom Data Tensor Internals Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go Provides access to the internal data structure of the custom tensor. ```go func (t *CustomDataTensor) GetInternals() *ValueInternalData ``` -------------------------------- ### Run DynamicAdvancedSession with Tensors Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go Executes the network with the provided input and output tensors. The number and order of tensors must match session initialization. Nil outputs will be allocated and must be freed. ```go func (s *DynamicAdvancedSession) Run(inputs, outputs []Value) error ``` -------------------------------- ### Create DynamicAdvancedSession from File Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go Creates a dynamic session without requiring pre-specification of input/output tensors. Input/output names can be nil if only using RunWithBinding. ```go func NewDynamicAdvancedSession(onnxFilePath string, inputNames, outputNames []string, opts *SessionOptions) (*DynamicAdvancedSession, error) ``` -------------------------------- ### Get Custom Data Tensor Data Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go Retrieves the raw byte slice backing the CustomDataTensor. This is the same slice passed during creation. ```go func (t *CustomDataTensor) GetData() []byte ``` -------------------------------- ### Create IoBinding for DynamicAdvancedSession Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go Creates an IoBinding instance for efficient data transfer to/from device memory. The IoBinding must be freed using Destroy(). ```go func (s *DynamicAdvancedSession) CreateIoBinding() (*IoBinding, error) ``` -------------------------------- ### Get Custom Data Tensor Data Type Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go Returns the ONNX tensor element data type of the custom tensor. ```go func (t *CustomDataTensor) DataType() C.ONNXTensorElementDataType ``` -------------------------------- ### Source Files Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go Lists the available source files for the onnxruntime-go package. ```APIDOC ## Source Files ΒΆ View all Source files * legacy_code.go * onnxruntime_go.go * setup_env.go * tensor_type_constraints.go ``` -------------------------------- ### Arena Configuration Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go Structures and constructors for configuring arena-based allocators. ```go type ArenaCfg struct { // contains filtered or unexported fields } ``` ```go func NewArenaCfg(maxMem int, arenaExtendStrategy, initialChunkSize, maxDeadBytesPerChunk int) (*ArenaCfg, error) ``` ```go func NewArenaCfgV2(configs map[string]int) (*ArenaCfg, error) ``` ```go func (c *ArenaCfg) Destroy() ``` -------------------------------- ### Get ONNX Map Shape Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go Use GetShape to obtain the shape of the map's keys Tensor, which indicates the number of key/value pairs. ```go func (m *Map) GetShape() Shape ``` -------------------------------- ### NewArenaCfgV2 Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go Creates an arena-based allocator configuration using string keys. Added in v1.26.0. ```APIDOC ## NewArenaCfgV2 ### Description NewArenaCfgV2 creates a configuration object for an arena-based allocator using string-based configuration keys and size_t values. Added in v1.26.0. ### Method func ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body - **configs** (map[string]int) - Required - A map of configuration keys and their integer values. ### Request Example N/A ### Response #### Success Response (200) - **(*ArenaCfg, error)**: Returns a pointer to ArenaCfg and an error if any occurred. #### Response Example N/A ``` -------------------------------- ### Get Model Metadata from DynamicAdvancedSession Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go Retrieves metadata for the model associated with the session. The returned metadata must be freed using its Destroy() function. ```go func (s *DynamicAdvancedSession) GetModelMetadata() (*ModelMetadata, error) ``` -------------------------------- ### Set Shared Library Path Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go Configures the location of the ONNX Runtime shared library. Must be called before InitializeEnvironment(). ```go func SetSharedLibraryPath(path string) ``` -------------------------------- ### NewAdvancedSession Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go Loads an ONNX network from a file path and initializes an AdvancedSession. ```APIDOC ## NewAdvancedSession ### Description Loads the ONNX network at the given path, and initializes an AdvancedSession instance. If this returns successfully, the caller must call Destroy() on the returned session when it is no longer needed. We require the user to provide the input and output tensors and names at this point, in order to not need to re-allocate them every time Run() is called. The user instead can just update or access the input/output tensor data after calling Run(). The input and output tensors MUST outlive this session, and calling session.Destroy() will not destroy the input or output tensors. If the provided SessionOptions pointer is nil, then the new session will use default options. ### Method func ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) - **(*AdvancedSession, error)**: Returns a pointer to an AdvancedSession and an error if any occurred. #### Response Example N/A ``` -------------------------------- ### Create AdvancedSession Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go Initializes an AdvancedSession from a file or byte slice. The caller must invoke Destroy() when finished. ```go func NewAdvancedSession(onnxFilePath string, inputNames, outputNames []string, inputs, outputs []Value, options *SessionOptions) (*AdvancedSession, error) ``` ```go func NewAdvancedSessionWithONNXData(onnxData []byte, inputNames, outputNames []string, inputs, outputs []Value, options *SessionOptions) (*AdvancedSession, error) ``` -------------------------------- ### Run Session Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go Executes the model inference using the session's configured tensors. ```go func (s *AdvancedSession) Run() error ``` ```go func (s *AdvancedSession) RunWithOptions(opts *RunOptions) error ``` -------------------------------- ### Get ONNX Map Keys and Values Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go Use GetKeysAndValues to retrieve the keys and values as separate Value tensors. These tensors should not be destroyed by the user as they are managed by the Map's lifecycle. They are distinct from the tensors passed during map creation. ```go func (m *Map) GetKeysAndValues() (Value, Value, error) ``` -------------------------------- ### Environment Management Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go Functions for initializing, configuring, and destroying the ONNX Runtime environment. ```APIDOC ## InitializeEnvironment ### Description Initializes the ONNX Runtime environment with optional configurations. ### Parameters - **opts** (...EnvironmentOption) - Optional - Configuration options such as log levels. ## DestroyEnvironment ### Description Cleans up and destroys the ONNX Runtime environment. ## SetEnvironmentLogLevel ### Description Sets the logging level for the environment. ### Parameters - **level** (LoggingLevel) - Required - The desired logging level. ``` -------------------------------- ### Create DynamicAdvancedSession from Data Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go Creates a dynamic session from byte data without requiring pre-specification of input/output tensors. Input/output names can be nil if only using RunWithBinding. ```go func NewDynamicAdvancedSessionWithONNXData(onnxData []byte, inputNames, outputNames []string, opts *SessionOptions) (*DynamicAdvancedSession, error) ``` -------------------------------- ### Create Deprecated DynamicSession from File Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go DEPRECATED: Use NewDynamicAdvancedSession instead. Creates a dynamic session from an ONNX file path. ```go func NewDynamicSession[in TensorData, out TensorData](onnxFilePath string, inputNames, outputNames []string) (*DynamicSession[in, out], error) ``` -------------------------------- ### Environment Options Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go Options for configuring the ORT Environment. ```APIDOC ## type EnvironmentOption EnvironmentOption is a functional option that can be provided during initialization of an ORT Environment. ### func WithLogLevelError ```go func WithLogLevelError() EnvironmentOption ``` WithLogLevelError is an EnvironmentOption that will set the ORT Environment logging to emit error messages along with all messages of greater severity. This is the default logging level. ### func WithLogLevelFatal ```go func WithLogLevelFatal() EnvironmentOption ``` WithLogLevelFatal is an EnvironmentOption that will set the ORT Environment logging to emit only fatal error messages (most severe). ### func WithLogLevelInfo ```go func WithLogLevelInfo() EnvironmentOption ``` WithLogLevelInfo is an EnvironmentOption that will set the ORT Environment logging to emit informational messages along with all messages of greater severity. ``` -------------------------------- ### NewArenaCfg Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go Creates a configuration object for an arena-based allocator. Added in v1.26.0. ```APIDOC ## NewArenaCfg ### Description NewArenaCfg creates a configuration object for an arena-based allocator. Added in v1.26.0. ### Method func ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) - **(*ArenaCfg, error)**: Returns a pointer to ArenaCfg and an error if any occurred. #### Response Example N/A ``` -------------------------------- ### Run Deprecated DynamicSession Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go DEPRECATED: Use DynamicAdvancedSession.Run() instead. Executes the network with the given input and output tensors. ```go func (s *DynamicSession[in, out]) Run(inputs []*Tensor[in], outputs []*Tensor[out]) error ``` -------------------------------- ### Update CUDA Provider Options Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go Configure CUDA backend settings by passing a map of string key-value pairs to the Update function. Refer to ONNX Runtime documentation for available configuration options. ```go func (o *CUDAProviderOptions) Update(options map[string]string) error ``` -------------------------------- ### Environment Management Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go Functions for initializing, destroying, and checking the status of the ONNX Runtime environment. ```APIDOC ## InitializeEnvironment ### Description Initializes the internal ONNX Runtime environment. Optionally accepts environment options. Must be called before most other ONNX Runtime functions. The caller is responsible for calling DestroyEnvironment when done. ### Method `func InitializeEnvironment(opts ...EnvironmentOption) error` ### Endpoint N/A (Internal function) ## DestroyEnvironment ### Description Cleans up the internal ONNX Runtime environment. Should be called when the environment is no longer needed. ### Method `func DestroyEnvironment() error` ### Endpoint N/A (Internal function) ## IsInitialized ### Description Checks if the ONNX Runtime package has been initialized. ### Method `func IsInitialized() bool` ### Endpoint N/A (Internal function) ``` -------------------------------- ### AdvancedSession.RunWithOptions Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go Executes the ONNX model with specified run options. Added in v1.23.0. ```APIDOC ## (*AdvancedSession) RunWithOptions ### Description RunWithOptions runs the session using the provided RunOptions. Added in v1.23.0. ### Method func (s *AdvancedSession) RunWithOptions(opts *RunOptions) error ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body - **opts** (*RunOptions) - Required - Options to configure the run. ### Request Example N/A ### Response #### Success Response (200) - **error**: Returns nil on success, or an error if execution failed. #### Response Example N/A ``` -------------------------------- ### RunOptions API Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go Manages run-time options for ONNX model execution, including cancellation. ```APIDOC ## NewRunOptions ### Description Creates a new OrtRunOptions instance. Must be closed when no longer needed. ### Method NewRunOptions ### Endpoint N/A (Function) ### Parameters None ### Request Example None ### Response #### Success Response - *RunOptions: A pointer to a new RunOptions instance. - error: An error if the instance cannot be created. #### Response Example None ``` ```APIDOC ## Destroy RunOptions ### Description Releases the underlying OrtRunOptions. ### Method (*RunOptions) Destroy ### Endpoint N/A (Method on struct) ### Parameters None ### Request Example None ### Response #### Success Response - error: An error if the destruction fails. #### Response Example None ``` ```APIDOC ## Terminate RunOptions ### Description Sets the terminate flag so any ongoing Run using this RunOptions fails quickly. ### Method (*RunOptions) Terminate ### Endpoint N/A (Method on struct) ### Parameters None ### Request Example None ### Response #### Success Response - error: An error if the termination fails. #### Response Example None ``` ```APIDOC ## UnsetTerminate RunOptions ### Description Clears the terminate flag so this RunOptions can be reused. ### Method (*RunOptions) UnsetTerminate ### Endpoint N/A (Method on struct) ### Parameters None ### Request Example None ### Response #### Success Response - error: An error if unsetting the terminate flag fails. #### Response Example None ``` -------------------------------- ### Set Environment Log Level to Info Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go An EnvironmentOption to set ORT Environment logging to emit informational messages and more severe ones. ```go func WithLogLevelInfo() EnvironmentOption ``` -------------------------------- ### SessionOptions Configuration Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go Methods for configuring ONNX Runtime session options such as threading, memory management, and optimization levels. ```APIDOC ## SessionOptions Configuration ### Description Methods to configure the behavior of an ONNX Runtime session. ### Methods - **HasSessionConfigEntry(key string)**: Checks for a configuration entry. - **SetCpuMemArena(isEnabled bool)**: Enables/disables CPU memory arena. - **SetExecutionMode(newMode ExecutionMode)**: Sets sequential or parallel execution mode. - **SetGraphOptimizationLevel(level GraphOptimizationLevel)**: Sets graph optimization level. - **SetInterOpNumThreads(n int)**: Sets threads for inter-op parallelism. - **SetIntraOpNumThreads(n int)**: Sets threads for intra-op parallelism. - **SetLogSeverityLevel(level LoggingLevel)**: Sets logging severity. - **SetMemPattern(isEnabled bool)**: Enables/disables memory pattern optimization. - **SetOptimizedModelFilePath(path string)**: Sets path to save optimized model. ``` -------------------------------- ### Logging Options Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go Functions to configure the logging level for the ONNX Runtime environment. ```APIDOC ## WithLogLevelVerbose ### Description Sets the ORT Environment logging to emit verbose informational messages (least severe) along with all messages of greater severity. ### Method `func()` ### Endpoint N/A (Function call) ### Parameters None ### Request Example ```go envOpt := onnxruntime.WithLogLevelVerbose() ``` ### Response #### Success Response (200) Returns an `EnvironmentOption`. #### Response Example N/A (Returns a type) ``` ```APIDOC ## WithLogLevelWarning ### Description Sets the ORT Environment logging to emit warning messages along with all messages of greater severity. ### Method `func()` ### Endpoint N/A (Function call) ### Parameters None ### Request Example ```go envOpt := onnxruntime.WithLogLevelWarning() ``` ### Response #### Success Response (200) Returns an `EnvironmentOption`. #### Response Example N/A (Returns a type) ``` -------------------------------- ### Map ZeroContents Method Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go The ZeroContents method for a Map is currently a no-op and exists for compatibility with the Value interface. ```go func (m *Map) ZeroContents() ``` -------------------------------- ### Create ONNX Map from Go Map Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go Use NewMapFromGoMap to wrap the creation of an ONNX map from a Go map. Type constraints for keys and values exist based on ONNX support, similar to NewMap. ```go func NewMapFromGoMap[K, V TensorData](m map[K]V) (*Map, error) ``` -------------------------------- ### SessionOptions API Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go API for configuring ONNX Runtime session options. ```APIDOC ## NewSessionOptions ### Description Initializes and returns a SessionOptions struct, used when setting options in new AdvancedSession instances. The caller must call the Destroy() function on the returned struct when it's no longer needed. ### Method ```go func NewSessionOptions() (*SessionOptions, error) ``` ### Parameters None ### Request Example ```json {} ``` ### Response #### Success Response (200) - **SessionOptions** (*SessionOptions) - A pointer to the newly created SessionOptions. - **error** (error) - An error if the initialization failed. #### Response Example ```json { "SessionOptions": "", "error": null } ``` ## SessionOptions ### Description Used to set options when creating an ONNXRuntime session. There is currently not a way to change options after the session is created, apart from destroying the session and creating a new one. This struct opaquely wraps a C OrtSessionOptions struct, which users must modify via function calls. Users must instantiate this struct using the NewSessionOptions function. Instances must be destroyed by calling the Destroy() method after the options are no longer needed (after NewAdvancedSession(...) has returned). ### Fields This struct contains filtered or unexported fields and is intended to be configured via functions like `NewSessionOptions`. ``` -------------------------------- ### I/O Binding Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go Manages the binding of input and output values for model execution with IoBinding. ```APIDOC ## IoBinding ### Description Wraps the OrtIoBinding instance. Must be created using DynamicAdvancedSession's CreateIoBinding method and Destroy'ed when no longer needed. Only DynamicAdvancedSession is supported for this, since a regular AdvancedSession requires specifying input and output tensors at session creation time. ### Methods #### BindInput - **Description**: Binds a value to the named input, to be used when RunWithBinding is called. - **Signature**: `func (b *IoBinding) BindInput(name string, value Value) error` #### BindOutput - **Description**: Binds a value to the named output, to be used when RunWithBinding is called. - **Signature**: `func (b *IoBinding) BindOutput(name string, value Value) error` #### ClearBoundInputs - **Description**: Clears any previously set inputs. Can't cause errors in the ORT C API. - **Signature**: `func (b *IoBinding) ClearBoundInputs() #### ClearBoundOutputs - **Description**: Clears any previously set outputs. Can't cause errors in the ORT C API. - **Signature**: `func (b *IoBinding) ClearBoundOutputs() #### Destroy - **Description**: Must be called to free resources associated with the IoBinding once it's no longer needed. - **Signature**: `func (b *IoBinding) Destroy() error` #### GetBoundOutputNames - **Description**: Returns a list of bound output names, which will be returned in the same order that outputs will be returned when GetBoundOutputValues is called. - **Signature**: `func (b *IoBinding) GetBoundOutputNames() ([]string, error)` #### GetBoundOutputValues - **Description**: Returns a list of Values containing results of a model run using RunWithBinding. The returned slice contains the same number of values as the number of names returned by GetOutputNames, and/or in the same order as they were bound using IoBinding.BindOutput. IMPORTANT: Each Value returned by this function must be freed by the caller; they are _copies_. Note: Using this function will cause Tensor contents to be copied from C-managed to Go-managed memory to avoid leaks (this is similar to behavior when DynamicAdvancedSession.Run is allowed to automatically allocate output tensors). Note that this may be expensive for larger tensors. - **Signature**: `func (b *IoBinding) GetBoundOutputValues() ([]Value, error) ``` -------------------------------- ### CreateAndRegisterAllocator Function Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go Creates a custom memory allocator and registers it with the ONNX Runtime environment. This allows the allocator to be shared across multiple sessions, potentially improving performance. ```go func CreateAndRegisterAllocator(memInfo *C.OrtMemoryInfo, cfg *ArenaCfg) error ``` -------------------------------- ### Training API (Deprecated) Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go Documentation for training-related functions which have been deprecated following the removal of the training API in onnxruntime 1.20.0. ```APIDOC ## Training API Status ### Description Support for TrainingSession and related functions has been removed from onnxruntime_go following the deprecation of the training API in onnxruntime 1.20.0. All functions listed below will return a TrainingAPIRemovedError. ### Functions - **GetInputOutputNames** - **NewTrainingSession** - **NewTrainingSessionWithOnnxData** - **Destroy** (on TrainingSession) - **ExportModel** (on TrainingSession) - **LazyResetGrad** (on TrainingSession) - **OptimizerStep** (on TrainingSession) - **SaveCheckpoint** (on TrainingSession) - **TrainStep** (on TrainingSession) ``` -------------------------------- ### DynamicSession API Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go Endpoints for creating and running dynamic sessions for model inference. ```APIDOC ## NewDynamicSession ### Description Creates a new dynamic session from an ONNX file path. ### Parameters - **onnxFilePath** (string) - Required - Path to the .onnx model file. - **inputNames** ([]string) - Required - List of input node names. - **outputNames** ([]string) - Required - List of output node names. ## Run ### Description Executes the model inference for a dynamic session. ### Parameters - **inputs** ([]*Tensor[in]) - Required - Input tensors. - **outputs** ([]*Tensor[out]) - Required - Output tensors to store results. ``` -------------------------------- ### CUDA Provider Options Management Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go Functions for initializing, configuring, and destroying CUDA provider options for ONNX Runtime sessions. ```APIDOC ## NewCUDAProviderOptions ### Description Initializes and returns a CUDAProviderOptions struct used to configure the CUDA backend. ### Method Function ### Parameters None ### Response - **CUDAProviderOptions** (struct) - The initialized options object. - **error** (error) - Returns an error if initialization fails. ## Update ### Description Configures the CUDA backend using a map of string keys and values. ### Parameters - **options** (map[string]string) - A map of configuration keys and values (e.g., "device_id": "1"). ## Destroy ### Description Frees internal C-allocated state for the CUDAProviderOptions struct. ``` -------------------------------- ### Session Options Configuration Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go Methods for setting and retrieving session configuration entries. ```APIDOC ## POST /api/session/config/entry ### Description Sets a session configuration key to the given value. If the key was already set, this will overwrite its old setting with the given value. ### Method POST ### Endpoint /api/session/config/entry ### Parameters #### Request Body - **key** (string) - Required - The configuration key to set. - **value** (string) - Required - The value to associate with the key. ### Request Example ```json { "key": "session_config_key", "value": "session_config_value" } ``` ### Response #### Success Response (200) - **message** (string) - Indicates successful configuration. #### Response Example ```json { "message": "Session configuration entry set successfully." } ``` ## GET /api/session/config/entry/{key} ### Description Returns the session config entry corresponding to the given key, or an error if one occurs. Returns an error if the key doesn't exist. ### Method GET ### Endpoint /api/session/config/entry/{key} ### Parameters #### Path Parameters - **key** (string) - Required - The configuration key to retrieve. ### Response #### Success Response (200) - **value** (string) - The value associated with the configuration key. #### Response Example ```json { "value": "session_config_value" } ``` ``` -------------------------------- ### Memory and Allocator Management Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go Functions for managing custom memory allocators and arena configurations. ```APIDOC ## CreateAndRegisterAllocator ### Description Creates and registers a memory allocator for the runtime. ### Parameters - **memInfo** (*C.OrtMemoryInfo) - Required - Memory information structure. - **arenaCfg** (*ArenaCfg) - Required - Arena configuration settings. ## NewArenaCfg ### Description Creates a new arena configuration for memory management. ### Parameters - **maxMem** (int) - Required - Maximum memory limit. - **arenaExtendStrategy** (int) - Required - Strategy for extending the arena. - **initialChunkSize** (int) - Required - Initial chunk size. - **maxDeadBytesPerChunk** (int) - Required - Maximum dead bytes allowed per chunk. ``` -------------------------------- ### NewAdvancedSessionWithONNXData Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go Initializes an AdvancedSession using ONNX model data provided as a byte slice. ```APIDOC ## NewAdvancedSessionWithONNXData ### Description The same as NewAdvancedSession, but takes a slice of bytes containing the .onnx network rather than a file path. ### Method func ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) - **(*AdvancedSession, error)**: Returns a pointer to an AdvancedSession and an error if any occurred. #### Response Example N/A ``` -------------------------------- ### AdvancedSession Structure Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go A wrapper for the OrtSession C struct requiring manual tensor management. ```go type AdvancedSession struct { // contains filtered or unexported fields } ``` -------------------------------- ### Enumerations Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go Wrappers for ONNX Runtime enumerations. ```APIDOC ## ExecutionMode ### Description Wraps the ExecutionMode enum in C. ### String Representation `func (m ExecutionMode) String() string` - Returns a string representation of the ExecutionMode. ``` ```APIDOC ## GraphOptimizationLevel ### Description Wraps the GraphOptimizationLevel enum in C. ### String Representation `func (l GraphOptimizationLevel) String() string` - Returns a string representation of the GraphOptimizationLevel. ``` ```APIDOC ## LoggingLevel ### Description Wraps the OrtLoggingLevel enum. ### String Representation `func (l LoggingLevel) String() string` - Returns a string representation of the LoggingLevel. ``` -------------------------------- ### CreateAndRegisterAllocator Function Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go Creates and registers an allocator with the environment for sharing between sessions. ```APIDOC ## func CreateAndRegisterAllocator ### Description Creates a new memory allocator and registers it with the ONNX Runtime environment. This allows the allocator to be shared across multiple inference sessions, potentially improving performance and reducing memory overhead. ### Method func ### Endpoint N/A (Function call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```go // Assuming memInfo and arenaCfg are properly initialized err := CreateAndRegisterAllocator(memInfo, arenaCfg) if err != nil { // Handle error } ``` ### Response #### Success Response (0) Returns `nil` if the allocator is created and registered successfully. #### Response Example `nil` ``` -------------------------------- ### TrainingSession Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go Manages the training process for ONNX models. ```APIDOC ## TrainingSession ### NewTrainingSession Creates a new TrainingSession. ### Method `func NewTrainingSession(...) (*TrainingSession, error)` ### NewTrainingSessionWithOnnxData Creates a new TrainingSession using ONNX model data in byte slices. ### Method `func NewTrainingSessionWithOnnxData(checkpointData, trainingData, evalData, optimizerData []byte, ...) (*TrainingSession, error)` ### Parameters #### Path Parameters - **checkpointData** ([]byte) - Required - Checkpoint data. - **trainingData** ([]byte) - Required - Training model data. - **evalData** ([]byte) - Required - Evaluation model data. - **optimizerData** ([]byte) - Required - Optimizer model data. ### Destroy Frees the resources associated with the TrainingSession. ### Method `func (s *TrainingSession) Destroy() error` ### ExportModel Exports the current model to a specified path with given output names. ### Method `func (s *TrainingSession) ExportModel(path string, outputNames []string) error` ### Parameters #### Path Parameters - **path** (string) - Required - The path to save the exported model. - **outputNames** ([]string) - Required - A list of output names for the exported model. ### LazyResetGrad Performs a lazy reset of gradients. ### Method `func (s *TrainingSession) LazyResetGrad() error` ### OptimizerStep Performs one step of the optimizer. ### Method `func (s *TrainingSession) OptimizerStep() error` ### SaveCheckpoint Saves the current training checkpoint to a specified path. ### Method `func (s *TrainingSession) SaveCheckpoint(path string, saveOptimizerState bool) error` ### Parameters #### Path Parameters - **path** (string) - Required - The path to save the checkpoint. - **saveOptimizerState** (bool) - Required - Whether to save the optimizer state. ``` -------------------------------- ### Allocator Management Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go Functions for creating, registering, and retrieving memory information for allocators. ```APIDOC ## CreateAndRegisterAllocatorV2 ### Description Creates and registers a custom allocator of a specific provider type with the ONNX Runtime environment. ### Method `func CreateAndRegisterAllocatorV2(providerType string, memInfo *C.OrtMemoryInfo, arenaCfg *ArenaCfg, options map[string]string) error` ### Endpoint N/A (Internal function) ## RegisterAllocator ### Description Registers a custom allocator with the ONNX Runtime environment. ### Method `func RegisterAllocator(allocator *C.OrtAllocator) error` ### Endpoint N/A (Internal function) ## GetMemoryInfo ### Description Retrieves the environment-wide OrtMemoryInfo. Useful for registering shared allocators. ### Method `func GetMemoryInfo() (*C.OrtMemoryInfo, error)` ### Endpoint N/A (Internal function) ``` -------------------------------- ### Set Environment Log Level to Fatal Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go An EnvironmentOption to set ORT Environment logging to emit only fatal error messages. ```go func WithLogLevelFatal() EnvironmentOption ``` -------------------------------- ### Session Options Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go Functions for configuring session options, such as setting optimized model file paths. ```APIDOC ## Session Options ### SetOptimizedModelFilePath Sets the file path for an optimized model. ### Method `func (o *SessionOptions) SetOptimizedModelFilePath(path string) error` ### Parameters #### Path Parameters - **path** (string) - Required - The file path to the optimized model. ``` -------------------------------- ### Utility Functions Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go Miscellaneous utility functions for ONNX Runtime. ```APIDOC ## GetTensorElementDataType ### Description Returns the ONNX enum value corresponding to a given TensorData type T. ### Method `func GetTensorElementDataType[T TensorData]() C.ONNXTensorElementDataType` ### Endpoint N/A (Internal function) ## GetVersion ### Description Returns the version of the ONNX Runtime library. ### Method `func GetVersion() string` ### Endpoint N/A (Internal function) ## IsTrainingSupported ### Description Indicates whether training is supported. Currently always returns false. ### Method `func IsTrainingSupported() bool` ### Endpoint N/A (Internal function) ## SetEnvironmentLogLevel ### Description Sets the environment-wide log severity level. Must be called after the environment has been initialized. ### Method `func SetEnvironmentLogLevel(level LoggingLevel) error` ### Endpoint N/A (Internal function) ``` -------------------------------- ### DynamicAdvancedSession Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go Represents a session that does not require specifying input and output tensors ahead of time. Users can pass the list of input and output tensors when calling Run(). Remember to call Destroy() when the session is no longer needed. ```APIDOC ## type DynamicAdvancedSession This type of session does not require specifying input and output tensors ahead of time, but allows users to pass the list of input and output tensors when calling Run(). As with AdvancedSession, users must still call Destroy() on an DynamicAdvancedSession that is no longer needed. ### func NewDynamicAdvancedSession ```go func NewDynamicAdvancedSession(onnxFilePath string, inputNames, outputNames []string, options *SessionOptions) (*DynamicAdvancedSession, error) ``` Like NewAdvancedSession, but does not require specifying input and output tensors. Input and output names can be nil or empty, but _only if_ this session will only be used via RunWithBinding, which manages names separately. ### func NewDynamicAdvancedSessionWithONNXData ```go func NewDynamicAdvancedSessionWithONNXData(onnxData []byte, inputNames, outputNames []string, options *SessionOptions) (*DynamicAdvancedSession, error) ``` Like NewAdvancedSessionWithONNXData, but does not require specifying input and output tensors. ### func (*DynamicAdvancedSession) CreateIoBinding ```go func (s *DynamicAdvancedSession) CreateIoBinding() (*IoBinding, error) ``` Creates and returns an IoBinding instance associated with the session. The I/O binding can be used to avoid unecessary copies to or from device memory, for sessions on different devices. The returned IoBinding must be freed using Destroy() when it is no longer needed. ### func (*DynamicAdvancedSession) Destroy ```go func (s *DynamicAdvancedSession) Destroy() error ``` ### func (*DynamicAdvancedSession) GetModelMetadata ```go func (s *DynamicAdvancedSession) GetModelMetadata() (*ModelMetadata, error) ``` Creates and returns a ModelMetadata instance for this session's model. The returned metadata must be freed using its Destroy() function when no longer needed. ### func (*DynamicAdvancedSession) Run ```go func (s *DynamicAdvancedSession) Run(inputs, outputs []Value) error ``` Runs the network on the given input and output tensors. The number of input and output tensors must match the number (and order) of the input and output names specified to NewDynamicAdvancedSession. If a given output is nil, it will be allocated and the slice will be modified to include the new Value. Any new Value allocated in this way must be freed by calling Destroy on it. ### func (*DynamicAdvancedSession) RunWithBinding ```go func (s *DynamicAdvancedSession) RunWithBinding(b *IoBinding) error ``` Runs the session using the given IoBinding instance. The IoBinding must have been created from this session's CreateIoBinding() function. ### func (*DynamicAdvancedSession) RunWithOptions ```go func (s *DynamicAdvancedSession) RunWithOptions(inputs, outputs []Value, opts *RunOptions) error ``` ``` -------------------------------- ### Define EnvironmentOption Type Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go A functional option for initializing an ORT Environment. ```go type EnvironmentOption func(*C.OrtEnv) *C.OrtStatus ``` -------------------------------- ### SetSharedLibraryPath Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go Sets the path to the ONNX Runtime shared library. This must be called before InitializeEnvironment(). ```APIDOC ## SetSharedLibraryPath ### Description Sets the path to the "onnxruntime.so" or "onnxruntime.dll" function. By default, it will be set to "onnxruntime.so" on non-Windows systems, and "onnxruntime.dll" on Windows. Users wishing to specify a particular location of this library must call this function prior to calling onnxruntime.InitializeEnvironment(). ### Method func ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) N/A #### Response Example N/A ``` -------------------------------- ### Logging Level Constants Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go Defines constants for logging levels, ranging from verbose to fatal. Use these to control the verbosity of ONNX Runtime logs. ```go const ( LoggingLevelVerbose = C.ORT_LOGGING_LEVEL_VERBOSE LoggingLevelInfo = C.ORT_LOGGING_LEVEL_INFO LoggingLevelWarning = C.ORT_LOGGING_LEVEL_WARNING LoggingLevelError = C.ORT_LOGGING_LEVEL_ERROR LoggingLevelFatal = C.ORT_LOGGING_LEVEL_FATAL ) ``` -------------------------------- ### Execution Mode Constants Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go Constants for specifying the execution mode of the ONNX Runtime. Choose between sequential or parallel execution. ```go const ( ExecutionModeSequential = C.ORT_SEQUENTIAL ExecutionModeParallel = C.ORT_PARALLEL ) ``` -------------------------------- ### NotInitializedError Variable Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go Error returned when the ONNX Runtime environment has not been initialized or initialization failed. Ensure InitializeRuntime() is called successfully before use. ```go var NotInitializedError error = fmt.Errorf("InitializeRuntime() has either " + "not yet been called, or did not return successfully") ``` -------------------------------- ### Session API (Deprecated) Source: https://pkg.go.dev/github.com/yalue/onnxruntime_go Deprecated functions for creating and managing ONNX Runtime sessions. ```APIDOC ## NewSession ### Description DEPRECATED: Use NewAdvancedSession instead. This function creates a new ONNX Runtime session from an ONNX model file. ### Method ```go func NewSession[T TensorData](onnxFilePath string, inputNames, outputNames []string, inputs, outputs []*Tensor[T]) (*Session[T], error) ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **onnxFilePath** (string) - Required - Path to the ONNX model file. - **inputNames** ([]string) - Required - Names of the input tensors. - **outputNames** ([]string) - Required - Names of the output tensors. - **inputs** ([]*Tensor[T]) - Required - Input tensors. - **outputs** ([]*Tensor[T]) - Required - Output tensors. ### Request Example ```json { "onnxFilePath": "/path/to/model.onnx", "inputNames": ["input1"], "outputNames": ["output1"], "inputs": [{"data": [1, 2, 3], "shape": [3]}], "outputs": [{"data": [], "shape": []}] } ``` ### Response #### Success Response (200) - **Session[T]** (*Session[T]) - A pointer to the newly created Session. - **error** (error) - An error if the session creation failed. #### Response Example ```json { "Session[T]": "", "error": null } ``` ## NewSessionWithONNXData ### Description DEPRECATED: Use NewAdvancedSessionWithONNXData instead. This function creates a new ONNX Runtime session from ONNX model data in bytes. ### Method ```go func NewSessionWithONNXData[T TensorData](onnxData []byte, inputNames, outputNames []string, inputs, outputs []*Tensor[T]) (*Session[T], error) ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **onnxData** ([]byte) - Required - The ONNX model data as a byte slice. - **inputNames** ([]string) - Required - Names of the input tensors. - **outputNames** ([]string) - Required - Names of the output tensors. - **inputs** ([]*Tensor[T]) - Required - Input tensors. - **outputs** ([]*Tensor[T]) - Required - Output tensors. ### Request Example ```json { "onnxData": "", "inputNames": ["input1"], "outputNames": ["output1"], "inputs": [{"data": [1, 2, 3], "shape": [3]}], "outputs": [{"data": [], "shape": []}] } ``` ### Response #### Success Response (200) - **Session[T]** (*Session[T]) - A pointer to the newly created Session. - **error** (error) - An error if the session creation failed. #### Response Example ```json { "Session[T]": "", "error": null } ``` ## Session Methods ### Session.Destroy #### Description Destroys the ONNX Runtime session. #### Method ```go func (s *Session[_]) Destroy() error ``` ### Session.Run #### Description Executes the ONNX model with the provided inputs and returns the outputs. #### Method ```go func (s *Session[T]) Run() error ``` ```