AINavi.Inference.Server
1.0.3-beta
This is a prerelease version of AINavi.Inference.Server.
dotnet add package AINavi.Inference.Server --version 1.0.3-beta
NuGet\Install-Package AINavi.Inference.Server -Version 1.0.3-beta
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AINavi.Inference.Server" Version="1.0.3-beta" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AINavi.Inference.Server" Version="1.0.3-beta" />
<PackageReference Include="AINavi.Inference.Server" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add AINavi.Inference.Server --version 1.0.3-beta
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: AINavi.Inference.Server, 1.0.3-beta"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package AINavi.Inference.Server@1.0.3-beta
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=AINavi.Inference.Server&version=1.0.3-beta&prerelease
#tool nuget:?package=AINavi.Inference.Server&version=1.0.3-beta&prerelease
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
AINavi Inference Server
一個適用於 Windows 平台的 AI 模型推理伺服器 SDK,提供簡單易用的 C# API 來載入和執行 AI 模型。支援分類、檢測、分割等多種模型類型,並可在 CPU 或 GPU 上進行推理運算。
📑 Table of Contents
系統需求
- 作業系統: Windows 10/11 (64位元)
- 運行環境: Visual Studio 2019 Redistributable
- Python 版本: Python 3.9
- 硬體需求:
- CPU: Intel/AMD 64位元處理器
- RAM: 最少 4GB,建議 8GB 以上
- GPU: 選配 (用於 GPU 加速推理)
作業需求
從 AINavi-Downloader 下載(如果沒有):
- AINavi Python 模組檔案:
C:\Program Files\Spingence\AINavi\ainavi_inference_server,並開通該模組的 Licence - AINavi 環境:
C:\Program Files\Spingence\AINavi\Envs\ainavi2_base - AINavi_Edgehub
快速開始
📦 安裝
透過 NuGet 安裝套件:
Install-Package inference_client
或使用 .NET CLI:
dotnet add package inference_client
🔧 基本使用
using inference_client;
const string pythonEnvPath = @"C:\Program Files\Spingence\AINavi\Envs\ainavi2_base";
using (var server = new InferenceServer())
{
// 初始化 Python 環境
if (!server.InitializePython(pythonEnvPath))
{
Console.WriteLine("Python 環境初始化失敗");
return;
}
// 載入模型
string modelPath = @"C:\Models\classification";
if (server.LoadModel("my_model", modelPath, "cpu"))
{
// 執行推理
string result = server.InferenceFromFile(@"C:\test.jpg", "my_model");
Console.WriteLine($"推理結果: {result}");
}
}
功能說明
1. 環境初始化
InitializePython(string pythonPath)
初始化 Python 解釋器環境。
參數:
pythonPath: Python 安裝路徑
返回值:
true: 初始化成功false: 初始化失敗
範例:
var server = new InferenceServer();
const string pythonEnvPath = @"C:\Program Files\Spingence\AINavi\Envs\ainavi2_base";
if (server.InitializePython(pythonEnvPath))
{
Console.WriteLine("Python 環境初始化成功");
}
資源管理方式
方式一:手動釋放
var server = new InferenceServer();
server.InitializePython(pythonEnvPath);
// ... 使用 server
server.Dispose(); // 手動釋放
方式二:自動釋放(建議)
using (var server = new InferenceServer())
{
server.InitializePython(pythonEnvPath);
// ... 使用 server
} // 自動釋放資源
2. 模型管理
LoadModel(string processorId, string modelPath, string device = "cpu")
載入單一 AI 模型到指定的處理器。
參數:
processorId: 處理器識別碼(自定義名稱)modelPath: 模型檔案路徑device: 運算設備"cpu": 使用 CPU"gpu"或"gpu:0": 使用第一個 GPU"gpu:1": 使用第二個 GPU
範例:
string modelPath = @"C:\Models\classification";
if (server.LoadModel("cls_model", modelPath, "gpu"))
{
Console.WriteLine("模型載入成功");
}
LoadModels(Dictionary<string, string> models, string device = "cpu")
批次載入多個 AI 模型。
範例:
var models = new Dictionary<string, string>
{
{ "model1", @"C:\Models\classification" },
{ "model2", @"C:\Models\detection" },
{ "model3", @"C:\Models\segmentation" }
};
if (server.LoadModels(models, "gpu"))
{
Console.WriteLine("所有模型批次載入成功");
}
SetCurrentProcessor(string processorId)
設定當前活躍的處理器。
server.SetCurrentProcessor("model1");
ResetModel(string processorId) / ResetAllModels()
重置特定模型或所有模型。
// 重置單一模型
server.ResetModel("model2");
// 重置所有模型
server.ResetAllModels();
3. 推理功能
InferenceFromFile(string imagePath, string processorId)
對單一檔案進行推理。
參數:
imagePath: 輸入檔案路徑processorId: 要使用的處理器識別碼
返回值:
- 推理結果(JSON 格式字串)
範例:
try
{
string imagePath = @"C:\TestImages\image.jpg";
string result = server.InferenceFromFile(imagePath, "cls_model");
Console.WriteLine($"推理結果: {result}");
}
catch (Exception ex)
{
Console.WriteLine($"推理錯誤: {ex.Message}");
}
使用範例
單一模型推理
using inference_client;
const string pythonEnvPath = @"C:\Program Files\Spingence\AINavi\Envs\ainavi2_base";
using (var server = new InferenceServer())
{
if (!server.InitializePython(pythonEnvPath))
{
Console.WriteLine("初始化失敗");
return;
}
string modelPath = @"C:\Models\classification";
if (server.LoadModel("cls_model", modelPath, "gpu"))
{
string imagePath = @"C:\TestImages\image.jpg";
string result = server.InferenceFromFile(imagePath, "cls_model");
Console.WriteLine($"推理結果: {result}");
}
}
多模型並行處理
using inference_client;
const string pythonEnvPath = @"C:\Program Files\Spingence\AINavi\Envs\ainavi2_base";
using (var server = new InferenceServer())
{
if (!server.InitializePython(pythonEnvPath))
{
return;
}
// 批次載入多個模型
var models = new Dictionary<string, string>
{
{ "model1", @"C:\Models\classification" },
{ "model2", @"C:\Models\detection" },
{ "model3", @"C:\Models\segmentation" }
};
if (server.LoadModels(models, "gpu"))
{
try
{
// 使用不同模型進行推理
string cls_result = server.InferenceFromFile(@"C:\TestImages\cls_test\image.jpg", "model1");
string det_result = server.InferenceFromFile(@"C:\TestImages\det_test\image.jpg", "model2");
string seg_result = server.InferenceFromFile(@"C:\TestImages\seg_test\image.jpg", "model3");
Console.WriteLine($"分類結果: {cls_result}");
Console.WriteLine($"檢測結果: {det_result}");
Console.WriteLine($"分割結果: {seg_result}");
}
catch (Exception ex)
{
Console.WriteLine($"推理錯誤: {ex.Message}");
}
}
}
注意事項
⚠️ 重要提醒
- 載入任何模型之前必須先初始化 Python 解釋器環境
- 重複呼叫
InitializePython()會直接返回成功 - 確保指定的 Python 路徑包含所需的依賴套件
- 建議使用
using語句自動管理資源釋放 - GPU 推理需要相容的 GPU 硬體和驅動程式
License
請參閱 AINavi 的授權條款。
Support
如有問題或需要技術支援,請聯繫 Spingence 技術支援團隊。
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
This package has no dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.3-beta | 178 | 10/30/2025 |
| 1.0.2-beta | 158 | 10/30/2025 |