Documentation ¶
Overview ¶
Package axlarod provides a Go wrapper for interacting with the Larod API, facilitating the management and execution of deep learning models on Axis devices.
The package includes types and functions for: - Establishing and terminating connections with the Larod service. - Querying, listing, and managing devices capable of running inference models. - Managing the lifecycle of models, including creation, execution, and resource cleanup. - Manipulating and transferring data between Go structures and the underlying hardware through Larod's memory management systems.
Index ¶
- Constants
- func AddPaddingToFrame(frame []byte, origWidth, origHeight, targetWidth, targetHeight int) []byte
- func ConvertRGBToImage(rgb []byte, width, height int) (*image.RGBA, error)
- func CopyDataFromMappedMemory(mappedAddr unsafe.Pointer, size int) ([]byte, error)
- func CopyDataToMappedMemory(mappedAddr unsafe.Pointer, data []byte) error
- func CreateAndMapTmpFile(fileNamePattern string, fileSize uint) (unsafe.Pointer, *os.File, error)
- func InizalizeModelComposer(larod *Larod, modelFilePath string, chipString string, modelInput *MemMapFile, ...) error
- func SaveImageAsJPEG(rgb []byte, width, height int, filename string) error
- type BoundingBox
- type Cords32
- type Cords64
- type Detection
- type JobRequest
- type JobResult
- type Larod
- func (l *Larod) Connect() error
- func (l *Larod) Connection() *LarodConnection
- func (l *Larod) DestroyInputTensors(model *LarodModel) error
- func (l *Larod) DestroyModel(model *LarodModel) error
- func (l *Larod) DestroyOutputTensors(model *LarodModel) error
- func (l *Larod) Disconnect() error
- func (l *Larod) ExecuteJob(model *LarodModel, dataSetterFunc func() error, ...) (*JobResult, error)
- func (l *Larod) GetDeviceByName(name string) (*LarodDevice, error)
- func (l *Larod) Initalize() error
- func (l *Larod) ListDevices() ([]*LarodDevice, error)
- func (l *Larod) LoadModel(file_path *string, dev *LarodDevice, access LarodAccess, name string, ...) (*LarodModel, error)
- func (l *Larod) LoadModelWithDeviceName(file_path *string, dev_name string, access LarodAccess, name string, ...) (*LarodModel, error)
- func (l *Larod) NewInferModel(filename, device string, model_defs MemMapConfiguration, job_params *LarodMap) (*LarodModel, error)
- func (l *Larod) NewPreProccessModel(device string, inputSize LarodResolution, outputSize LarodResolution, ...) (*LarodModel, error)
- type LarodAccess
- type LarodConnection
- type LarodDevice
- type LarodError
- type LarodErrorCode
- type LarodMap
- func (m *LarodMap) Destroy()
- func (m *LarodMap) GetIntArr2(key string) ([2]int64, error)
- func (m *LarodMap) GetIntArr4(key string) ([4]int64, error)
- func (m *LarodMap) GetStr(key string) (string, error)
- func (m *LarodMap) SetInt(key string, value int64) error
- func (m *LarodMap) SetIntArr2(key string, value [2]int64) error
- func (m *LarodMap) SetIntArr4(key string, value [4]int64) error
- func (m *LarodMap) SetStr(key, value string) error
- type LarodMapEntries
- type LarodMapValueType
- type LarodModel
- func (model *LarodModel) CreateJobRequest(inputTensors []*LarodTensor, outputTensors []*LarodTensor, params *LarodMap) (*JobRequest, error)
- func (model *LarodModel) CreateModelInputs() ([]*LarodTensor, uint, error)
- func (model *LarodModel) CreateModelOutputs() ([]*LarodTensor, uint, error)
- func (model *LarodModel) CreateModelTensors(model_defs *MemMapConfiguration) error
- func (m *LarodModel) Destroy()
- func (model *LarodModel) Execute(conn *LarodConnection) error
- func (model *LarodModel) MapModelTmpFiles(m *MemMapConfiguration) error
- func (m *LarodModel) RewindAllOutputsMemMapFiles() error
- type LarodResolution
- type LarodTensor
- func (tensor *LarodTensor) CopyDataInto(data []byte) error
- func (tensor *LarodTensor) GetData(size int) ([]byte, error)
- func (tensor *LarodTensor) GetDataAsFloat32() (float32, error)
- func (tensor *LarodTensor) GetDataAsFloat32Slice(size int) ([]float32, error)
- func (tensor *LarodTensor) GetDataAsInt() (int, error)
- func (tensor *LarodTensor) GetDataType() (LarodTensorDataType, error)
- func (tensor *LarodTensor) GetTensorPitches() (*LarodTensorPitches, error)
- func (tensor *LarodTensor) SetTensorFd(fd uintptr) error
- type LarodTensorDataType
- type LarodTensorLayout
- type LarodTensorPitches
- type MemMapConfiguration
- type MemMapFile
- type ModelComposer
- type PreProccessOutputFormat
- type PreProccessOutputMode
Constants ¶
const LAROD_TENSOR_MAX_LEN = 12 // Maximum length of the tensor.
Variables ¶
This section is empty.
Functions ¶
func AddPaddingToFrame ¶ added in v1.2.8
addPaddingToFrame adds padding to an RGB frame to achieve a new target size. Parameters: - frame: the original RGB frame as a byte slice - origWidth: the original width of the frame - origHeight: the original height of the frame - targetWidth: the target width to pad the frame to - targetHeight: the target height to pad the frame to Returns: a new frame with padding added as a byte slice
func ConvertRGBToImage ¶
ConvertRGBToImage converts raw RGB bytes to an image.Image object
func CopyDataFromMappedMemory ¶
CopyDataFromMappedMemory copies data from the mapped memory
func CopyDataToMappedMemory ¶
CopyDataToMappedMemory copies data to the mapped memory
func CreateAndMapTmpFile ¶
CreateAndMapTmpFile creates a temporary file and maps it to memory
func InizalizeModelComposer ¶ added in v1.2.4
func InizalizeModelComposer(larod *Larod, modelFilePath string, chipString string, modelInput *MemMapFile, modelComposer *ModelComposer) error
InitializeModelComposer initializes a model composer with the necessary information to compose a model for inference.
Types ¶
type BoundingBox ¶
BoundingBox is a struct that holds the coordinates of a bounding box in float32
func (*BoundingBox) Scale ¶
func (bbox *BoundingBox) Scale(w, h int) BoundingBox
Scale scales the bounding box to the given width and height
func (*BoundingBox) ToCords32 ¶
func (bbox *BoundingBox) ToCords32() Cords32
ToCords32 converts the bounding box to Cords32
func (*BoundingBox) ToCords64 ¶
func (bbox *BoundingBox) ToCords64() Cords64
ToCords64 converts the bounding box to Cords64
type Detection ¶ added in v1.2.4
type Detection struct { Box BoundingBox Confidence float32 ClassIndex int ClassLabel string }
Detection is a struct that holds the information of a detection.
type JobRequest ¶
type JobRequest struct {
// contains filtered or unexported fields
}
func (*JobRequest) Destroy ¶
func (job *JobRequest) Destroy()
DestroyJobRequest cleans up resources associated with a JobRequest.
type Larod ¶
type Larod struct { Devices []*LarodDevice // contains filtered or unexported fields }
func NewLarod ¶
func NewLarod() *Larod
NewLarod creates a new Larod instance with uninitialized connection and device list.
func (*Larod) Connection ¶
func (l *Larod) Connection() *LarodConnection
Connection returns the current connection to the Larod service.
func (*Larod) DestroyInputTensors ¶
func (l *Larod) DestroyInputTensors(model *LarodModel) error
DestroyInputTensors cleans up resources associated with input tensors of a LarodModel.
func (*Larod) DestroyModel ¶
func (l *Larod) DestroyModel(model *LarodModel) error
DestroyModel cleans up resources associated with a LarodModel.
func (*Larod) DestroyOutputTensors ¶
func (l *Larod) DestroyOutputTensors(model *LarodModel) error
DestroyOutputTensors cleans up resources associated with output tensors of a LarodModel.
func (*Larod) Disconnect ¶
Disconnect terminates the connection with the Larod service.
func (*Larod) ExecuteJob ¶
func (l *Larod) ExecuteJob(model *LarodModel, dataSetterFunc func() error, dataGetterFunc func() (any, error)) (*JobResult, error)
ExecuteJob orchestrates the execution of a model with data setting and retrieving processes. It measures the execution time and returns a JobResult with the execution time and the output data. If any step (setting data, executing the model, or retrieving data) fails, it returns an error detailing the failure.
func (*Larod) GetDeviceByName ¶
func (l *Larod) GetDeviceByName(name string) (*LarodDevice, error)
GetDeviceByName searches for a device by name among the cached devices in a Larod instance.
func (*Larod) Initalize ¶
Initialize establishes a connection to the Larod service and retrieves a list of available devices. It handles errors that occur during the connection or device listing process.
func (*Larod) ListDevices ¶
func (l *Larod) ListDevices() ([]*LarodDevice, error)
ListDevices queries and lists all devices managed by a Larod instance's connection.
func (*Larod) LoadModel ¶
func (l *Larod) LoadModel(file_path *string, dev *LarodDevice, access LarodAccess, name string, params *LarodMap) (*LarodModel, error)
LarodLoadModel loads a new model onto a specified device.
func (*Larod) LoadModelWithDeviceName ¶
func (l *Larod) LoadModelWithDeviceName(file_path *string, dev_name string, access LarodAccess, name string, params *LarodMap) (*LarodModel, error)
LoadModelWithDeviceName loads a new model onto a specified device by name.
func (*Larod) NewInferModel ¶
func (l *Larod) NewInferModel(filename, device string, model_defs MemMapConfiguration, job_params *LarodMap) (*LarodModel, error)
NewInferModel creates a new model for inference, just a tiny wrapper around LoadModelWithDeviceName, CreateModelTensors and CreateJobRequest
func (*Larod) NewPreProccessModel ¶
func (l *Larod) NewPreProccessModel(device string, inputSize LarodResolution, outputSize LarodResolution, outputFormat PreProccessOutputFormat, job_params *LarodMap) (*LarodModel, error)
NewPreProccessModel creates a new pre-processing model with the specified device, input size, output size, and output format.
type LarodAccess ¶
type LarodAccess int
const ( LarodAccessInvalid LarodAccess = iota LarodAccessPrivate LarodAccessPublic )
type LarodConnection ¶
type LarodConnection struct {
// contains filtered or unexported fields
}
type LarodDevice ¶
type LarodDevice struct { Name string // contains filtered or unexported fields }
func (*LarodDevice) GetName ¶
func (dev *LarodDevice) GetName() (string, error)
GetName retrieves the name of a LarodDevice.
type LarodError ¶
type LarodError struct { Code LarodErrorCode Msg string }
func (*LarodError) Error ¶
func (l *LarodError) Error() string
type LarodErrorCode ¶
type LarodErrorCode int
const ( LarodErrorNone LarodErrorCode = 0 LarodErrorJob LarodErrorCode = -1 LarodErrorLoadModel LarodErrorCode = -2 LarodErrorFD LarodErrorCode = -3 LarodErrorModelNotFound LarodErrorCode = -4 LarodErrorPermission LarodErrorCode = -5 LarodErrorConnection LarodErrorCode = -6 LarodErrorCreateSession LarodErrorCode = -7 LarodErrorKillSession LarodErrorCode = -8 LarodErrorInvalidChipID LarodErrorCode = -9 LarodErrorInvalidAccess LarodErrorCode = -10 LarodErrorDeleteModel LarodErrorCode = -11 LarodErrorTensorMismatch LarodErrorCode = -12 LarodErrorVersionMismatch LarodErrorCode = -13 LarodErrorAlloc LarodErrorCode = -14 LarodErrorMaxErrno LarodErrorCode = 1024 )
type LarodMap ¶
type LarodMap struct {
// contains filtered or unexported fields
}
LarodMap wraps a pointer to a larodMap, which is a key-value store for parameters used in Larod operations.
func CreateCropMap ¶
func CreateCropMap(inputWidth int, inputHeight int, streamWidth int, streamHeight int) (*LarodMap, error)
CreateCropMap creates a LarodMap with the crop values for the input and stream dimensions
func NewLarodMap ¶
NewLarodMap creates a new LarodMap instance, initializing the underlying larodMap.
func NewLarodMapWithEntries ¶
func NewLarodMapWithEntries(entries []*LarodMapEntries) (*LarodMap, error)
NewLarodMapWithEntries creates a new LarodMap and populates it with the provided entries.
func (*LarodMap) Destroy ¶
func (m *LarodMap) Destroy()
Destroy cleans up resources associated with the LarodMap.
func (*LarodMap) GetIntArr2 ¶
GetIntArr2 retrieves an array of two int64 values from the map by its key.
func (*LarodMap) GetIntArr4 ¶
GetIntArr4 retrieves an array of four int64 values from the map by its key.
func (*LarodMap) SetIntArr2 ¶
SetIntArr2 stores an array of two int64 values in the map with the provided key.
func (*LarodMap) SetIntArr4 ¶
SetIntArr4 stores an array of four int64 values in the map with the provided key.
type LarodMapEntries ¶
type LarodMapEntries struct { Key string // Key of the entry. Value interface{} // Value of the entry, can be of different types based on ValueType. ValueType LarodMapValueType // Type of the value stored. }
LarodMapEntries represents a key-value pair to be used in a LarodMap.
type LarodMapValueType ¶
type LarodMapValueType int
LarodMapValueType enumerates the types of values that can be stored in a LarodMap.
const ( LarodMapValueTypeInt LarodMapValueType = iota LarodMapValueTypeStr LarodMapValueTypeIntArr2 LarodMapValueTypeIntArr4 )
type LarodModel ¶
type LarodModel struct { Fd uintptr Job *JobRequest Name string Inputs []*LarodTensor InputsCount uint InputPitches *LarodTensorPitches Outputs []*LarodTensor OutputsCount uint OutputPitches *LarodTensorPitches // contains filtered or unexported fields }
func (*LarodModel) CreateJobRequest ¶
func (model *LarodModel) CreateJobRequest(inputTensors []*LarodTensor, outputTensors []*LarodTensor, params *LarodMap) (*JobRequest, error)
CreateJobRequest initializes a job request for a model using specified input and output tensors and optional parameters.
func (*LarodModel) CreateModelInputs ¶
func (model *LarodModel) CreateModelInputs() ([]*LarodTensor, uint, error)
CreateModelInputs allocates and returns pointers to input tensors for a model, along with the count of these tensors.
func (*LarodModel) CreateModelOutputs ¶
func (model *LarodModel) CreateModelOutputs() ([]*LarodTensor, uint, error)
CreateModelOutputs allocates and returns pointers to output tensors for a model, along with the count of these tensors.
func (*LarodModel) CreateModelTensors ¶
func (model *LarodModel) CreateModelTensors(model_defs *MemMapConfiguration) error
CreateModelTensors initializes and configures model tensors according to provided memory configurations.
func (*LarodModel) Destroy ¶
func (m *LarodModel) Destroy()
LoadModelWithDeviceID loads a new model onto a specified device by ID.
func (*LarodModel) Execute ¶
func (model *LarodModel) Execute(conn *LarodConnection) error
Execute runs a job using a LarodModel on a given LarodConnection. It submits the job described by model.Job for execution.
func (*LarodModel) MapModelTmpFiles ¶
func (model *LarodModel) MapModelTmpFiles(m *MemMapConfiguration) error
MapModelTmpFiles maps the temporary files for the model.
func (*LarodModel) RewindAllOutputsMemMapFiles ¶
func (m *LarodModel) RewindAllOutputsMemMapFiles() error
Seek the memory mapped file to the beginning for all output tensors.
type LarodResolution ¶
func (*LarodResolution) RgbSize ¶
func (lr *LarodResolution) RgbSize() uint
func (*LarodResolution) ToArray ¶
func (lr *LarodResolution) ToArray() [2]int64
type LarodTensor ¶
type LarodTensor struct { MemMapFile *MemMapFile // contains filtered or unexported fields }
LarodTensor encapsulates a tensor structure with a pointer to its C representation.
func (*LarodTensor) CopyDataInto ¶
func (tensor *LarodTensor) CopyDataInto(data []byte) error
CopyDataInto copies data into the memory mapped file associated with a tensor.
func (*LarodTensor) GetData ¶
func (tensor *LarodTensor) GetData(size int) ([]byte, error)
GetData retrieves data from the memory mapped file associated with a tensor.
func (*LarodTensor) GetDataAsFloat32 ¶
func (tensor *LarodTensor) GetDataAsFloat32() (float32, error)
GetDataAsFloat32 retrieves a single float32 value from the memory mapped file associated with a tensor.
func (*LarodTensor) GetDataAsFloat32Slice ¶
func (tensor *LarodTensor) GetDataAsFloat32Slice(size int) ([]float32, error)
GetDataAsFloat32Slice retrieves data from the memory mapped file associated with a tensor and converts it to a float32 slice.
func (*LarodTensor) GetDataAsInt ¶
func (tensor *LarodTensor) GetDataAsInt() (int, error)
func (*LarodTensor) GetDataType ¶
func (tensor *LarodTensor) GetDataType() (LarodTensorDataType, error)
Get data type of a tensor.
func (*LarodTensor) GetTensorPitches ¶
func (tensor *LarodTensor) GetTensorPitches() (*LarodTensorPitches, error)
GetTensorPitches retrieves the pitch information of a tensor and converts it to a Go struct.
func (*LarodTensor) SetTensorFd ¶
func (tensor *LarodTensor) SetTensorFd(fd uintptr) error
SetTensorFd sets the file descriptor of a tensor.
type LarodTensorDataType ¶
type LarodTensorDataType int
LarodTensorDataType defines different data types that a tensor can represent.
const ( LarodTensorDataTypeInvalid LarodTensorDataType = iota LarodTensorDataTypeUnspecified LarodTensorDataTypeBool LarodTensorDataTypeUint8 LarodTensorDataTypeInt8 LarodTensorDataTypeUint16 LarodTensorDataTypeInt16 LarodTensorDataTypeUint32 LarodTensorDataTypeInt32 LarodTensorDataTypeUint64 LarodTensorDataTypeInt64 LarodTensorDataTypeFloat16 LarodTensorDataTypeFloat32 LarodTensorDataTypeFloat64 LarodTensorDataTypeMax )
type LarodTensorLayout ¶
type LarodTensorLayout int
LarodTensorLayout represents the memory layout of a tensor.
const ( LarodTensorLayoutInvalid LarodTensorLayout = iota LarodTensorLayoutUnspecified LarodTensorLayoutNHWC // NHWC layout: channels last LarodTensorLayoutNCHW // NCHW layout: channels first LarodTensorLayout420SP // 420SP layout: semi-planar YCbCr format LarodTensorLayoutMax )
type LarodTensorPitches ¶
type LarodTensorPitches struct { Pitches [LAROD_TENSOR_MAX_LEN]uint Len uint }
LarodTensorPitches represents the memory layout pitches of a tensor.
type MemMapConfiguration ¶
type MemMapConfiguration struct { InputTmpMapFiles map[int]*MemMapFile OutputTmpMapFiles map[int]*MemMapFile }
MemMapConfiguration represents the configuration for memory mapped files.
type MemMapFile ¶
type MemMapFile struct { MemoryAddress unsafe.Pointer File *os.File Size uint FilePattern string UsePitch0Size bool }
MemMapFile represents a memory mapped file.
func (*MemMapFile) Rewind ¶
func (t *MemMapFile) Rewind() error
Seek the memory mapped file to the beginning
func (*MemMapFile) UnmapMemory ¶
func (t *MemMapFile) UnmapMemory() error
UnmapMemory unmaps the memory mapped file
type ModelComposer ¶ added in v1.2.4
type ModelComposer struct { Labels []string DequantizeFunc func(byte) float32 OutputParser func(rawModelOuput []float32, mc *ModelComposer) []Detection Threshold float32 IouThreshold float64 OutputTensorPitches *LarodTensorPitches // contains filtered or unexported fields }
ModelComposer is a struct that holds the necessary information to compose a model for inference. It contains the labels, dequantization function, output parser, model, threshold, Larod instance, IoU threshold, and output tensor pitches. Its suppose to be used to compose a model for inference, with the necessary information to do so.
func (*ModelComposer) Clean ¶ added in v1.2.4
func (mc *ModelComposer) Clean() error
Clean cleans the model.
func (*ModelComposer) Inference ¶ added in v1.2.4
func (mc *ModelComposer) Inference() (*JobResult, error)
Inference runs the inference of the model.
type PreProccessOutputFormat ¶
type PreProccessOutputFormat string
var ( PreProccessOutputFormatRgbInterleaved PreProccessOutputFormat = "rgb-interleaved" PreProccessOutputFormatRgbPlanar PreProccessOutputFormat = "rgb-planar" )
type PreProccessOutputMode ¶ added in v1.2.8
type PreProccessOutputMode int
var ( PreProccessOutputModeCrop PreProccessOutputMode = 0 PreProccessOutputModePadding PreProccessOutputMode = 1 )