/// <summary> /// Load ONNX file and make model_data /// </summary> /// <param name="onnx_model_path"></param> /// <returns></returns> public static ModelData MakeModelDataFromONNX(string onnx_model_path) { IntPtr handle = IntPtr.Zero; Utils.Check(DLL.menoh_make_model_data_from_onnx(onnx_model_path, ref handle)); return(new ModelData() { handle = handle, }); }
/// <summary> /// Factory function for model /// </summary> /// <param name="model_data"></param> /// <param name="backend_name"></param> /// <param name="backend_config"></param> /// <returns></returns> public Model BuildModel(ModelData model_data, string backend_name, string backend_config = "") { IntPtr handle = IntPtr.Zero; Utils.Check(DLL.menoh_build_model(this.handle, model_data.handle, backend_name, backend_config, ref handle)); return(new Model() { handle = handle, }); }
/// <summary> /// Factory function for variable_profile_table. /// </summary> /// <param name="model_data"></param> /// <returns></returns> public VariableProfileTable BuildVariableProfileTable(ModelData model_data) { IntPtr handle = IntPtr.Zero; Utils.Check(DLL.menoh_build_variable_profile_table(this.handle, model_data.handle, ref handle)); return(new VariableProfileTable() { handle = handle, }); }
public void Dispose() { lock (this) { if (handle != IntPtr.Zero) { DLL.menoh_delete_model(handle); handle = IntPtr.Zero; } System.GC.SuppressFinalize(this); } }
public void Dispose() { lock (this) { if (handle != IntPtr.Zero) { DLL.menoh_delete_variable_profile_table_builder(handle); handle = IntPtr.Zero; } System.GC.SuppressFinalize(this); } }
/// <summary> /// Load ONNX file from memory and make model_data /// </summary> /// <param name="onnx_data"></param> /// <returns></returns> public static unsafe ModelData MakeModelDataFromONNXDataOnMemory(byte[] onnx_data) { fixed(byte *p = onnx_data) { IntPtr handle = IntPtr.Zero; Utils.Check(DLL.menoh_make_model_data_from_onnx_data_on_memory((IntPtr)p, onnx_data.Length, ref handle)); return(new ModelData() { handle = handle, }); } }
/// <summary> /// Add input profile. That profile contains name, dtype and dims. /// </summary> /// <param name="name"></param> /// <param name="dtype"></param> /// <param name="dims"></param> public void AddInputProfile(string name, DType dtype, int[] dims) { if (dims.Length == 2) { Utils.Check(DLL.menoh_variable_profile_table_builder_add_input_profile_dims_2(handle, name, dtype, dims[0], dims[1])); } else if (dims.Length == 4) { Utils.Check(DLL.menoh_variable_profile_table_builder_add_input_profile_dims_4(handle, name, dtype, dims[0], dims[1], dims[2], dims[3])); } else { throw new Exception(string.Format("menoh invalid dims size error (2 or 4 is valid): dims size of {0} is specified {1}", name, dims.Length)); } }
/// <summary> /// Optimize model_data. /// </summary> /// <param name="vpt"></param> /// <remarks> /// This function modify internal state of model_data. /// </remarks> public void Optimize(VariableProfileTable vpt) { Utils.Check(DLL.menoh_model_data_optimize(handle, vpt.handle)); }
/// <summary> /// Run model inference. /// </summary> public void Run() { Utils.Check(DLL.menoh_model_run(handle)); }
/// <summary> /// Users can attach external buffers to variables. /// </summary> /// <param name="name"></param> /// <param name="buffer_handle"></param> /// <remarks> /// Variables attached no external buffer are attached internal buffers allocated automatically. /// </remarks> public void AttachExternalBuffer(string name, IntPtr buffer_handle) { Utils.Check(DLL.menoh_model_builder_attach_external_buffer(handle, name, buffer_handle)); }
public ModelBuilder(VariableProfileTable variable_profile_table) { Utils.Check(DLL.menoh_make_model_builder(variable_profile_table.handle, ref handle)); }
public void AddOutputProfile(string name, DType dtype) { Utils.Check(DLL.menoh_variable_profile_table_builder_add_output_profile(handle, name, dtype)); }
/// <summary> /// Add output name /// </summary> /// <param name="name"></param> /// <remarks> /// dims amd dtype of output are calculated automatically when calling of menoh_build_variable_profile_table. /// </remarks> public void AddOutputName(string name) { Utils.Check(DLL.menoh_variable_profile_table_builder_add_output_name(handle, name)); }
/// <summary> /// Add input profile. That profile contains name, dtype and dims. /// </summary> /// <param name="name"></param> /// <param name="dtype"></param> /// <param name="dims"></param> public void AddInputProfile(string name, DType dtype, int[] dims) { Utils.Check(DLL.menoh_variable_profile_table_builder_add_input_profile(handle, name, dtype, dims.Length, dims)); }
public VariableProfileTableBuilder() { Utils.Check(DLL.menoh_make_variable_profile_table_builder(ref handle)); }