예제 #1
0
        /// <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,
            });
        }
예제 #2
0
        /// <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,
            });
        }
예제 #3
0
        /// <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,
            });
        }
예제 #4
0
 public void Dispose()
 {
     lock (this)
     {
         if (handle != IntPtr.Zero)
         {
             DLL.menoh_delete_model(handle);
             handle = IntPtr.Zero;
         }
         System.GC.SuppressFinalize(this);
     }
 }
예제 #5
0
 public void Dispose()
 {
     lock (this)
     {
         if (handle != IntPtr.Zero)
         {
             DLL.menoh_delete_variable_profile_table_builder(handle);
             handle = IntPtr.Zero;
         }
         System.GC.SuppressFinalize(this);
     }
 }
예제 #6
0
        /// <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,
                });
            }
        }
예제 #7
0
 /// <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));
     }
 }
예제 #8
0
 /// <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));
 }
예제 #9
0
 /// <summary>
 /// Run model inference.
 /// </summary>
 public void Run()
 {
     Utils.Check(DLL.menoh_model_run(handle));
 }
예제 #10
0
 /// <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));
 }
예제 #11
0
 public ModelBuilder(VariableProfileTable variable_profile_table)
 {
     Utils.Check(DLL.menoh_make_model_builder(variable_profile_table.handle, ref handle));
 }
예제 #12
0
 public void AddOutputProfile(string name, DType dtype)
 {
     Utils.Check(DLL.menoh_variable_profile_table_builder_add_output_profile(handle, name, dtype));
 }
예제 #13
0
 /// <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));
 }
예제 #14
0
 /// <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));
 }
예제 #15
0
 public VariableProfileTableBuilder()
 {
     Utils.Check(DLL.menoh_make_variable_profile_table_builder(ref handle));
 }