---@meta onnxruntime

--------------------------------------------------------------------------------
-- ONNX Runtime 模块
--------------------------------------------------------------------------------

---@alias onnxruntime_tensor_type
---| '"float32"'
---| '"float"'
---| '"float16"'
---| '"bfloat16"'
---| '"uint8"'
---| '"uint16"'
---| '"int8"'
---| '"int16"'
---| '"int32"'
---| '"uint32"'
---| '"int64"'
---| '"uint64"'
---| '"double"'
---| '"float64"'
---| '"bool"'
---| '"string"'

---@alias onnxruntime_shape integer[]
---@alias onnxruntime_tensor_data number|boolean|string|number[]|boolean[]|string[]|table
---@alias onnxruntime_value_like onnxruntime_tensor*|onnxruntime_value*|onnxruntime_sequence*|onnxruntime_map*|onnxruntime_sparse_tensor*
---@alias onnxruntime_tensor_or_scalar onnxruntime_tensor*|number|boolean
---@alias onnxruntime_named_values table<string|integer, onnxruntime_value_like>

---@class onnxruntime_config*
---@field log_severity_level? integer 日志级别
---@field log_id? string 日志标识
---@field use_global_thread_pools? boolean 是否使用全局线程池
---@field global_intra_op_num_threads? integer intra-op 线程数
---@field global_inter_op_num_threads? integer inter-op 线程数

---@class onnxruntime_session_options*
---@field intra_op_num_threads? integer intra-op 线程数
---@field inter_op_num_threads? integer inter-op 线程数
---@field execution_mode? integer|string 执行模式
---@field graph_optimization_level? integer|string 图优化级别
---@field optimized_model_filepath? string 优化模型输出路径
---@field enable_profiling? boolean 是否启用 profiling
---@field profiling_prefix? string profiling 前缀
---@field log_id? string 日志标识
---@field log_severity_level? integer 日志级别
---@field log_verbosity_level? integer 日志详细级别
---@field use_coreml? boolean 是否启用 CoreML EP
---@field coreml_flags? integer CoreML EP flags
---@field use_cpu? boolean 是否启用 CPU EP
---@field custom_op_libraries? onnxruntime_custom_op_library*[] 自定义算子库

---@class onnxruntime_run_options*
---@field tag? string run tag
---@field log_severity_level? integer 日志级别
---@field log_verbosity_level? integer 日志详细级别

---@class onnxruntime_image_tensor_options*
---@field width? integer 输出宽
---@field height? integer 输出高
---@field add_batch? boolean 是否添加 batch 维度
---@field layout? '"nchw"'|'"nhwc"'|'"chw"'|'"hwc"' 张量布局
---@field channel_order? '"rgb"'|'"bgr"'|'"gray"'|'"grey"'|'"grayscale"' 通道顺序
---@field scale? number 像素缩放
---@field data_type? onnxruntime_tensor_type 张量类型
---@field resize_mode? '"stretch"'|'"letterbox"'|'"center_crop"' 缩放模式
---@field letterbox_mode? '"center"'|'"top_left"'|'"topleft"' letterbox 对齐方式
---@field pad_color? integer 填充颜色
---@field interpolation? '"nearest"'|'"bilinear"' 插值方式
---@field alpha_mode? '"ignore"'|'"white"'|'"black"'|'"premultiply"' alpha 处理方式
---@field crop? { x: integer, y: integer, width: integer, height: integer } 裁剪区域
---@field mean? number|number[] 均值
---@field std? number|number[] 标准差

---@class onnxruntime_image_tensor_meta*
---@field src_width integer 原图宽
---@field src_height integer 原图高
---@field crop_x integer 裁剪 X
---@field crop_y integer 裁剪 Y
---@field crop_width integer 裁剪宽
---@field crop_height integer 裁剪高
---@field dst_width integer 目标宽
---@field dst_height integer 目标高
---@field resized_width integer 缩放后宽
---@field resized_height integer 缩放后高
---@field layout string 布局
---@field channel_order string 通道顺序
---@field resize_mode string 缩放模式
---@field scale_x number X 缩放
---@field scale_y number Y 缩放
---@field ratio number 缩放比例
---@field offset_x integer X 偏移
---@field offset_y integer Y 偏移
---@field pad_left integer 左填充
---@field pad_top integer 上填充
---@field pad_right integer 右填充
---@field pad_bottom integer 下填充

---@class onnxruntime_image_from_tensor_options*
---@field layout? '"nchw"'|'"nhwc"'|'"chw"'|'"hwc"' 张量布局
---@field channel_order? '"rgb"'|'"bgr"'|'"gray"' 通道顺序
---@field batch_index? integer batch 索引，从 1 开始
---@field scale? number 输出缩放
---@field mean? number|number[] 均值
---@field std? number|number[] 标准差
---@field clamp? boolean 是否裁剪到 0..255
---@field range01? boolean 是否按 0..1 范围反归一化

---@class onnxruntime_type_info*
---@field name? string 名称
---@field onnx_type string ONNX 类型
---@field is_sparse? boolean 是否稀疏
---@field data_type? string Tensor 元素类型
---@field type? string 类型描述
---@field has_shape? boolean 是否有 shape
---@field shape? integer[] shape
---@field symbolic_shape? table symbolic shape
---@field element? onnxruntime_type_info 序列元素类型
---@field key_type? string map key 类型
---@field value? onnxruntime_type_info map value 类型

---@class onnxruntime_memory_info*
---@field name string allocator 名称
---@field id integer device id
---@field mem_type integer memory type
---@field allocator_type integer allocator type
---@field device_type? integer device type
---@field device_mem_type? integer device memory type
---@field vendor_id? integer vendor id

---@class onnxruntime_metadata*
---@field producer_name? string producer
---@field graph_name? string graph
---@field domain? string domain
---@field description? string description
---@field graph_description? string graph description
---@field version integer version
---@field custom_metadata table<string, string> 自定义 metadata

---@class onnxruntime_nms_options*
---@field score_threshold? number 分数阈值
---@field iou_threshold? number IoU 阈值
---@field max_detections? integer 最大保留数量
---@field class_agnostic? boolean 是否忽略类别

---@class onnxruntime_box_record*
---@field box number[] 框
---@field score number 分数
---@field class_id integer 类别
---@field row_index? integer 原始行索引
---@field x1? number
---@field y1? number
---@field x2? number
---@field y2? number
---@field width? number
---@field height? number
---@field cx? number
---@field cy? number

---@class onnxruntime_obb_record*
---@field cx number 中心 X
---@field cy number 中心 Y
---@field w number 宽
---@field h number 高
---@field theta number 角度
---@field score number 分数
---@field class_id integer 类别
---@field row_index? integer 原始行索引

---@class onnxruntime_keypoint*
---@field x number X
---@field y number Y
---@field score? number 分数
---@field raw? number[] 原始值

---@class onnxruntime_track*
---@field id integer track id
---@field box number[] 框
---@field score number 分数
---@field class_id? integer 类别
---@field age integer 年龄
---@field hits integer 命中次数
---@field first_seen integer 首次出现帧
---@field last_seen integer 最近出现帧

---@class onnxruntime_mask_bitmap*
---@field width integer 宽
---@field height integer 高
---@field bits string 位图数据
---@field pixel_count integer 像素数
---@field bounds? table 边界

---@class onnxruntime_ctc_result*
---@field text? string 文本
---@field indices integer[] token 索引
---@field confidence? number 置信度
---@field probabilities? number[][] 概率
---@field probability_confidence? number 概率置信度

---@class onnxruntime_tensor*
local tensor = {}

--- 获取张量 shape。
---@return integer[] shape
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:shape() end

--- 获取张量 rank。
---@return integer rank
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:rank() end

--- 获取元素数量。
---@return integer size
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:size() end

--- 获取元素类型。
---@return onnxruntime_tensor_type type
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:type() end

--- 转为 Lua table。
---@return table data
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:to_table() end

--- 返回底层字节串，string tensor 不支持。
---@return string bytes
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:bytes() end

--- 转为 image.cv mat。
---@param opts? table 选项
---@return image_cv_mat* mat
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:to_cv_mat(opts) end

--- 读取元素，索引按 Lua 习惯从 1 开始。
---@param ... integer 索引
---@return any value
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:get(...) end

--- 写入元素，最后一个参数是值。
---@param ... any 索引和值
---@return boolean ok
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:set(...) end

--- 填充张量。
---@param value onnxruntime_tensor_data 标量或元素表
---@return boolean ok
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:fill(value) end

--- 改变 shape。
---@param shape integer[] 新 shape
---@return onnxruntime_tensor* tensor
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:reshape(shape) end

--- 转置维度。
---@param axes? integer[] 维度顺序
---@return onnxruntime_tensor* tensor
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:transpose(axes) end

--- 展平维度区间。
---@param start_dim? integer 起始维度
---@param end_dim? integer 结束维度
---@return onnxruntime_tensor* tensor
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:flatten(start_dim, end_dim) end

--- 删除 size 为 1 的维度。
---@param dim? integer 指定维度
---@return onnxruntime_tensor* tensor
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:squeeze(dim) end

--- 插入 size 为 1 的维度。
---@param dim integer 插入位置
---@return onnxruntime_tensor* tensor
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:unsqueeze(dim) end

--- 克隆张量。
---@return onnxruntime_tensor* tensor
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:clone() end

--- 转换元素类型。
---@param type onnxruntime_tensor_type 目标类型
---@return onnxruntime_tensor* tensor
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:to(type) end

--- 切片。
---@param dim integer 维度
---@param start integer 起点，从 1 开始
---@param stop integer 终点，包含
---@param step? integer 步长
---@return onnxruntime_tensor* tensor
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:slice(dim, start, stop, step) end

--- 选择某个维度的一个索引并删除该维度。
---@param dim integer 维度
---@param index integer 索引，从 1 开始
---@return onnxruntime_tensor* tensor
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:select(dim, index) end

--- 按索引收集。
---@param dim integer 维度
---@param indices integer[]|onnxruntime_tensor* 索引，从 1 开始
---@return onnxruntime_tensor* tensor
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:gather(dim, indices) end

---@param rhs onnxruntime_tensor_or_scalar 右值
---@return onnxruntime_tensor*|number result
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:add(rhs) end

---@param rhs onnxruntime_tensor_or_scalar 右值
---@return onnxruntime_tensor*|number result
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:sub(rhs) end

---@param rhs onnxruntime_tensor_or_scalar 右值
---@return onnxruntime_tensor*|number result
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:mul(rhs) end

---@param rhs onnxruntime_tensor_or_scalar 右值
---@return onnxruntime_tensor*|number result
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:div(rhs) end

---@param min_value number 最小值
---@param max_value number 最大值
---@return onnxruntime_tensor* tensor
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:clamp(min_value, max_value) end

---@return onnxruntime_tensor* tensor
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:sigmoid() end

---@return onnxruntime_tensor* tensor
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:exp() end

---@param rhs onnxruntime_tensor* 右矩阵
---@return onnxruntime_tensor* tensor
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:matmul(rhs) end

---@param axis? integer 维度；省略时返回全局最大索引
---@return onnxruntime_tensor*|integer result
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:argmax(axis) end

---@param axis? integer 维度
---@return onnxruntime_tensor*|number result
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:sum(axis) end

---@param axis? integer 维度
---@return onnxruntime_tensor*|number result
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:mean(axis) end

---@param axis? integer 维度
---@return onnxruntime_tensor*|number result
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:max(axis) end

---@param axis? integer 维度
---@return onnxruntime_tensor*|number result
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:min(axis) end

---@param axis? integer 维度
---@return onnxruntime_tensor* tensor
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:softmax(axis) end

---@param opts? table 选项
---@return onnxruntime_tensor* tensor
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:normalize(opts) end

---@param axis? integer 维度
---@param descending? boolean 是否降序
---@return onnxruntime_tensor* values
---@return onnxruntime_tensor* indices
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:sort(axis, descending) end

---@param rhs onnxruntime_tensor* 右值
---@return number dot 点积
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:dot(rhs) end

---@param k integer k
---@param axis? integer 维度
---@return onnxruntime_tensor* values
---@return onnxruntime_tensor* indices
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:topk(k, axis) end

---@param bytes string 原始字节
---@return boolean ok
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:copy_from_bytes(bytes) end

---@class onnxruntime_value*
local value = {}

---@return string type 类型描述
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime)
---
function value:type() end

---@return boolean ok 是否有值
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime)
---
function value:has_value() end

---@return any value 值
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime)
---
function value:get() end

---@class onnxruntime_sequence*: onnxruntime_value*
local sequence = {}

---@return string type 类型描述
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime)
---
function sequence:type() end

---@return boolean ok 是否有值
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime)
---
function sequence:has_value() end

---@param index integer 索引，从 1 开始
---@return onnxruntime_value_like value
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime)
---
function sequence:get(index) end

---@return integer length 长度
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime)
---
function sequence:length() end

---@return onnxruntime_value_like[] items 元素数组
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime)
---
function sequence:items() end

---@class onnxruntime_map*: onnxruntime_value*
local map = {}

---@return string type 类型描述
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime)
---
function map:type() end

---@return boolean ok 是否有值
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime)
---
function map:has_value() end

---@param key any key
---@return any value
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime)
---
function map:get(key) end

---@param key any key
---@param value any value
---@return boolean ok
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime)
---
function map:set(key, value) end

---@return any[] keys
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime)
---
function map:keys() end

---@return table pairs
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime)
---
function map:pairs() end

---@class onnxruntime_sparse_tensor*: onnxruntime_value*
local sparse_tensor = {}

---@return string type 类型描述
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime)
---
function sparse_tensor:type() end

---@return boolean ok 是否有值
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime)
---
function sparse_tensor:has_value() end

---@return any value
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime)
---
function sparse_tensor:get() end

---@return integer[] shape dense shape
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime)
---
function sparse_tensor:dense_shape() end

---@return onnxruntime_tensor* values 稀疏值
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime)
---
function sparse_tensor:values() end

---@return onnxruntime_tensor* indices 索引
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime)
---
function sparse_tensor:indices() end

---@return string format 稀疏格式
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime)
---
function sparse_tensor:format() end

---@return onnxruntime_tensor* tensor dense tensor
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime)
---
function sparse_tensor:to_dense() end

---@class onnxruntime_session*
local session = {}

---@param inputs onnxruntime_named_values 输入
---@param outputs? string[]|table 输出名称；省略时返回全部输出
---@param run_options? onnxruntime_run_options_object* 运行选项
---@return onnxruntime_named_values outputs 输出
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function session:run(inputs, outputs, run_options) end

---@param inputs onnxruntime_named_values 输入
---@param outputs table<string|integer, onnxruntime_tensor*> 输出复用表
---@param run_options? onnxruntime_run_options_object* 运行选项
---@return onnxruntime_named_values outputs 输出
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function session:run_into(inputs, outputs, run_options) end

---@param binding onnxruntime_io_binding* IO binding
---@param run_options? onnxruntime_run_options_object* 运行选项
---@return onnxruntime_io_binding* binding
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function session:run_with_iobinding(binding, run_options) end

---@return onnxruntime_io_binding* binding
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function session:create_io_binding() end

---@return string[] names
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function session:input_names() end

---@return string[] names
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function session:output_names() end

---@return string[] names
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function session:overridable_initializer_names() end

---@return integer count
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function session:input_count() end

---@return integer count
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function session:output_count() end

---@return integer count
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function session:overridable_initializer_count() end

---@param name_or_index string|integer 名称或索引
---@return onnxruntime_type_info* info
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function session:input_info(name_or_index) end

---@param name_or_index string|integer 名称或索引
---@return onnxruntime_type_info* info
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function session:output_info(name_or_index) end

---@param name_or_index string|integer 名称或索引
---@return onnxruntime_type_info* info
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function session:overridable_initializer_info(name_or_index) end

---@return table<string|integer, onnxruntime_memory_info*> infos
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function session:memory_info_for_inputs() end

---@return table<string|integer, onnxruntime_memory_info*> infos
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function session:memory_info_for_outputs() end

---@return onnxruntime_metadata* metadata
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function session:metadata() end

---@return boolean ok
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function session:close() end

---@return string? path profiling 文件路径
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function session:end_profiling() end

---@return number time_ns profiling 开始时间
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function session:profiling_start_time_ns() end

---@param options table<string, any> EP 动态选项
---@return boolean ok
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function session:set_ep_dynamic_options(options) end

---@param library onnxruntime_custom_op_library* 自定义算子库
---@return boolean ok
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function session:register_custom_op_library(library) end

---@class onnxruntime_io_binding*
local io_binding = {}

---@param name string 输入名
---@param value onnxruntime_value_like 输入值
---@return boolean ok
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function io_binding:bind_input(name, value) end

---@param name string 输出名
---@param value_or_spec? onnxruntime_tensor*|{ mode?: '"device"', type?: onnxruntime_tensor_type, shape?: integer[] } 输出张量或规格
---@return boolean|onnxruntime_tensor* result
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function io_binding:bind_output(name, value_or_spec) end

---@return boolean ok
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function io_binding:clear_inputs() end

---@return boolean ok
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function io_binding:clear_outputs() end

---@return onnxruntime_named_values outputs
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function io_binding:get_outputs() end

---@return boolean ok
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function io_binding:synchronize_inputs() end

---@return boolean ok
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function io_binding:synchronize_outputs() end

---@class onnxruntime_run_options_object*
local run_options_object = {}

---@param tag? string 新 tag
---@return string? tag 当前 tag
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function run_options_object:tag(tag) end

---@param level? integer 新日志级别
---@return integer level 当前日志级别
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function run_options_object:log_severity_level(level) end

---@param level? integer 新日志详细级别
---@return integer level 当前日志详细级别
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function run_options_object:log_verbosity_level(level) end

---@return boolean ok
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function run_options_object:terminate() end

---@return boolean ok
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function run_options_object:reset_terminate() end

---@class onnxruntime_custom_op_library*
local custom_op_library = {}

---@class onnxruntime_decoder*
local decoder = {}

---@param outputs table<string, any>|onnxruntime_named_values 模型输出
---@param opts? table 选项
---@return any result 解码结果
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function decoder:decode(outputs, opts) end

---@return string task 任务名
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function decoder:task() end

---@return table schema schema
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function decoder:schema() end

---@class onnxruntime_tracker*
local tracker = {}

---@param detections table[] 检测结果
---@param opts? table 选项
---@return onnxruntime_track[] tracks
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tracker:update(detections, opts) end

---@return boolean ok
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tracker:reset() end

---@return onnxruntime_track[] tracks
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tracker:state() end

---@return boolean ok
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tracker:close() end

---@class onnxruntime*
---@type onnxruntime*
local M = {}

--- 获取 ONNX Runtime 版本。
---@return string version
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime)
---
function M.version() end

--- 获取可用执行提供器。
---@return string[] providers
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime)
---
function M.providers() end

--- 配置全局 runtime，需在创建 session 前调用。
---@param opts onnxruntime_config* 配置
---@return boolean ok
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function M.configure(opts) end

--- 创建张量。
---@param type onnxruntime_tensor_type 元素类型
---@param shape integer[] shape
---@param data? onnxruntime_tensor_data 初始数据或标量
---@return onnxruntime_tensor* tensor
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.tensor(type, shape, data) end

--- 从字节创建数值张量。
---@param type onnxruntime_tensor_type 元素类型
---@param shape integer[] shape
---@param bytes string 原始字节
---@return onnxruntime_tensor* tensor
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.tensor_from_bytes(type, shape, bytes) end

--- 从 image.cv mat 创建张量。
---@param mat image_cv_mat* mat
---@param type? onnxruntime_tensor_type 元素类型
---@return onnxruntime_tensor* tensor
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.tensor_from_cv_mat(mat, type) end

--- 从图片四边形区域创建张量。
---@param image ImageObject* 图片
---@param quad table 四边形
---@param opts? onnxruntime_image_tensor_options* 选项
---@return onnxruntime_tensor* tensor
---@return onnxruntime_image_tensor_meta* meta
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.tensor_from_quad(image, quad, opts) end

--- 从多个图片四边形区域创建 batch 张量。
---@param image ImageObject* 图片
---@param quads table[] 四边形数组
---@param opts? onnxruntime_image_tensor_options* 选项
---@return onnxruntime_tensor* tensor
---@return onnxruntime_image_tensor_meta[] metas
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.tensor_from_quads(image, quads, opts) end

--- 从图片创建张量。
---@param image ImageObject* 图片
---@param opts? onnxruntime_image_tensor_options* 选项
---@return onnxruntime_tensor* tensor
---@return onnxruntime_image_tensor_meta* meta
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.tensor_from_image(image, opts) end

--- 从图片数组创建 batch 张量。
---@param images ImageObject*[] 图片数组
---@param opts? onnxruntime_image_tensor_options* 选项
---@return onnxruntime_tensor* tensor
---@return onnxruntime_image_tensor_meta[] metas
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.tensor_from_images(images, opts) end

--- 从图像张量创建图片。
---@param tensor onnxruntime_tensor* 张量
---@param opts? onnxruntime_image_from_tensor_options* 选项
---@return ImageObject* image
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.image_from_tensor(tensor, opts) end

---@param tensor onnxruntime_tensor* 输入
---@param min_value number 最小值
---@param max_value number 最大值
---@return onnxruntime_tensor* tensor
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.clamp(tensor, min_value, max_value) end

---@param tensor onnxruntime_tensor* 输入
---@return onnxruntime_tensor* tensor
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.sigmoid(tensor) end

---@param tensor onnxruntime_tensor* 输入
---@return onnxruntime_tensor* tensor
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.exp(tensor) end

---@param condition onnxruntime_tensor* 条件
---@param then_value onnxruntime_tensor_or_scalar true 值
---@param else_value onnxruntime_tensor_or_scalar false 值
---@return onnxruntime_tensor* tensor
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.where(condition, then_value, else_value) end

---@param lhs onnxruntime_tensor* 左矩阵
---@param rhs onnxruntime_tensor* 右矩阵
---@return onnxruntime_tensor* tensor
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.matmul(lhs, rhs) end

---@param tensors onnxruntime_tensor*[] 张量数组
---@param axis integer 拼接维度
---@return onnxruntime_tensor* tensor
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.concat(tensors, axis) end

---@param tensors onnxruntime_tensor*[] 张量数组
---@param axis integer 新维度
---@return onnxruntime_tensor* tensor
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.stack(tensors, axis) end

--- 非极大值抑制。
---@param boxes onnxruntime_tensor*|number[][] boxes
---@param scores onnxruntime_tensor*|number[] scores
---@param opts? onnxruntime_nms_options* 选项
---@return integer[] keep_indices 保留索引
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.nms(boxes, scores, opts) end

---@param box onnxruntime_tensor*|number[] 旋转框
---@return table points 顶点
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.box_points(box) end

---@param boxes onnxruntime_tensor* boxes
---@return onnxruntime_tensor* boxes
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.xywh_to_xyxy(boxes) end

---@param boxes onnxruntime_tensor* boxes
---@return onnxruntime_tensor* boxes
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.xyxy_to_xywh(boxes) end

---@param boxes1 onnxruntime_tensor* boxes1
---@param boxes2 onnxruntime_tensor* boxes2
---@return onnxruntime_tensor* iou
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.rotated_iou(boxes1, boxes2) end

---@param boxes onnxruntime_tensor* boxes
---@param scores onnxruntime_tensor* scores
---@param opts? table 选项
---@return integer[] keep_indices
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.rotated_nms(boxes, scores, opts) end

---@param schema table|string decoder schema
---@return onnxruntime_decoder* decoder
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.create_decoder(schema) end

---@param outputs table<string, any>|onnxruntime_named_values 模型输出
---@param opts? table 选项
---@return table records
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.decode_yolo(outputs, opts) end

---@param outputs table<string, any>|onnxruntime_named_values 模型输出
---@param opts? table 选项
---@return table records
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.decode_yolo_obb(outputs, opts) end

---@param tensor onnxruntime_tensor* 候选矩阵张量
---@param schema table|string decoder schema
---@param opts? table 选项
---@return table candidates
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.decode_matrix_candidates(tensor, schema, opts) end

---@param boxes onnxruntime_tensor* boxes
---@param scores onnxruntime_tensor* scores
---@param class_ids onnxruntime_tensor* class ids
---@param keep_indices? onnxruntime_tensor* keep indices
---@return onnxruntime_box_record[] records
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.records_from_boxes(boxes, scores, class_ids, keep_indices) end

---@param rows onnxruntime_tensor* rows
---@param opts? table 选项
---@return onnxruntime_obb_record[] records
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.obb_records_from_rows(rows, opts) end

---@param points onnxruntime_tensor* points
---@param opts? table 选项
---@return onnxruntime_keypoint[] records
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.points_to_records(points, opts) end

---@param outputs table<string, any>|onnxruntime_named_values 模型输出
---@param opts? table 选项
---@return table detections
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.decode_dense_detection(outputs, opts) end

---@param pred onnxruntime_tensor* DB 模型预测张量
---@param opts? table 选项
---@return table result
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.db_postprocess(pred, opts) end

---@param masks onnxruntime_tensor* masks
---@param threshold? number 阈值
---@return onnxruntime_mask_bitmap[] masks
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.threshold_masks(masks, threshold) end

---@param masks onnxruntime_tensor* masks
---@param boxes onnxruntime_tensor* boxes
---@param opts? table 选项
---@return onnxruntime_tensor* masks
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.crop_masks_by_boxes(masks, boxes, opts) end

---@param masks onnxruntime_tensor* masks
---@param width integer 目标宽
---@param height integer 目标高
---@param opts? table 选项
---@return onnxruntime_tensor* masks
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.resize_masks(masks, width, height, opts) end

---@param masks1 onnxruntime_mask_bitmap* masks1
---@param masks2 onnxruntime_mask_bitmap* masks2
---@param opts? table 选项
---@return number iou
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.mask_iou(masks1, masks2, opts) end

---@param mask onnxruntime_tensor*|onnxruntime_mask_bitmap* mask
---@param opts? table 选项
---@return table polygon
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.mask_to_polygon(mask, opts) end

---@param prototypes onnxruntime_tensor* prototypes
---@param coefficients onnxruntime_tensor* coefficients
---@param boxes onnxruntime_tensor* boxes
---@param width integer 图片宽度
---@param height integer 图片高度
---@param opts? table 选项
---@return onnxruntime_mask_bitmap[] masks
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.proto_masks(prototypes, coefficients, boxes, width, height, opts) end

---@param prototypes onnxruntime_tensor* prototypes
---@param coefficients onnxruntime_tensor* coefficients
---@param boxes onnxruntime_tensor* boxes
---@param width integer 图片宽度
---@param height integer 图片高度
---@param opts? table 选项
---@return onnxruntime_mask_bitmap[] masks
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.project_masks(prototypes, coefficients, boxes, width, height, opts) end

---@param opts? table 选项
---@return onnxruntime_tracker* tracker
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.tracker(opts) end

---@param tensor onnxruntime_tensor* 输入
---@param opts? table 选项
---@return onnxruntime_tensor* tensor
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.reshape_keypoints(tensor, opts) end

---@param boxes onnxruntime_tensor* boxes
---@param transform onnxruntime_image_tensor_meta*|table transform
---@return onnxruntime_tensor* boxes
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.scale_boxes(boxes, transform) end

---@param boxes onnxruntime_tensor* boxes
---@param width number 宽
---@param height number 高
---@return onnxruntime_tensor* boxes
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.clip_boxes(boxes, width, height) end

---@param points onnxruntime_tensor* points
---@param transform onnxruntime_image_tensor_meta*|table transform
---@param opts? table 选项
---@return onnxruntime_tensor* points
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.scale_points(points, transform, opts) end

---@param keypoints onnxruntime_tensor* keypoints
---@param transform onnxruntime_image_tensor_meta*|table transform
---@param opts? table 选项
---@return onnxruntime_tensor* keypoints
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.scale_keypoints(keypoints, transform, opts) end

---@param keypoints onnxruntime_tensor* keypoints
---@param width number 宽
---@param height number 高
---@param opts? table 选项
---@return onnxruntime_tensor* keypoints
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.clip_keypoints(keypoints, width, height, opts) end

---@param logits onnxruntime_tensor* logits
---@param alphabet string[]|table 字符表
---@param opts? table 选项
---@return onnxruntime_ctc_result|onnxruntime_ctc_result[] result
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.ctc_greedy_decode(logits, alphabet, opts) end

---@param logits onnxruntime_tensor* logits
---@param opts? table 选项
---@return integer token_index
---@return number probability
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.sample_logits(logits, opts) end

---@param value any Lua 值
---@param type_decl? string 显式类型声明
---@return onnxruntime_value_like value
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime)
---
function M.value(value, type_decl) end

---@param type_decl string optional 内部类型声明
---@param value? any 值
---@return onnxruntime_value* value
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime)
---
function M.optional(type_decl, value) end

---@param values any[] 序列元素
---@param type_decl? string 元素类型声明
---@return onnxruntime_sequence* sequence
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime)
---
function M.sequence(values, type_decl) end

---@param key_type string key 类型
---@param value_type string value 类型
---@param values table 初始值
---@return onnxruntime_map* map
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime)
---
function M.map(key_type, value_type, values) end

---@param type onnxruntime_tensor_type 元素类型
---@param dense_shape integer[] dense shape
---@param indices integer[]|integer[][] COO indices
---@param values number[] values
---@return onnxruntime_sparse_tensor* sparse_tensor
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime)
---
function M.sparse_tensor(type, dense_shape, indices, values) end

---@param tensor onnxruntime_tensor* dense tensor
---@return onnxruntime_sparse_tensor* sparse_tensor
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime)
---
function M.sparse_tensor_from_dense(tensor) end

---@param model_path string 模型路径
---@param opts? onnxruntime_session_options* 选项
---@return onnxruntime_session* session
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function M.session(model_path, opts) end

---@param model_bytes string 模型字节
---@param opts? onnxruntime_session_options* 选项
---@return onnxruntime_session* session
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function M.session_from_bytes(model_bytes, opts) end

---@param opts? onnxruntime_run_options* 选项
---@return onnxruntime_run_options_object* options
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function M.run_options(opts) end

---@param path string 动态库路径
---@return onnxruntime_custom_op_library* library
---
---[查看文档](https://xxtouch.app/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function M.load_custom_op_library(path) end

return M
