IntptrMax.YoloSharp
1.1.19
dotnet add package IntptrMax.YoloSharp --version 1.1.19
NuGet\Install-Package IntptrMax.YoloSharp -Version 1.1.19
<PackageReference Include="IntptrMax.YoloSharp" Version="1.1.19" />
<PackageVersion Include="IntptrMax.YoloSharp" Version="1.1.19" />
<PackageReference Include="IntptrMax.YoloSharp" />
paket add IntptrMax.YoloSharp --version 1.1.19
#r "nuget: IntptrMax.YoloSharp, 1.1.19"
#:package IntptrMax.YoloSharp@1.1.19
#addin nuget:?package=IntptrMax.YoloSharp&version=1.1.19
#tool nuget:?package=IntptrMax.YoloSharp&version=1.1.19
YoloSharp
Train Yolo model in C# with TorchSharp. <br/> With the help of this project you won't have to transform .pt model to onnx, and can train your own model in C# and don't have to install python.
Feature
- Written in C# only, don't have to install python.
- Train and predict your own model.
- Support Yolov5, Yolov5u, Yolov8, Yolov11 and Yolov12 now.
- Support Predict, Segment, Obb, Pose(Key Points) and Classification now.
- Support n/s/m/l/x size.
- Support LetterBox and Mosaic4 method for preprocessing images.
- Support NMS with GPU.
- Support Load PreTrained models from ultralytics yolov5/yolov8/yolo11 and yolov12(converted).
- Support .Net6 or higher.
π₯Important News
2026/03/06
π Add config for training and predict.
π Add more metrics for val.
2026/02/03
π Add Early Stop.
π Add HSV transform.
π Add Train Logs.
2026/01/20
π YoloSharp support Mixed Precision Trainer (simple amp)
π Tqdm supported.
π Add BF16 Precision.
Models
You can download yolo pre-trained models here.
<details>
<summary>Prediction Checkpoints</summary>
| model | n | s | m | l | x |
|---|---|---|---|---|---|
| yolov5 | yolov5n | yolov5s | yolov5m | yolov5l | yolov5x |
| yolov5 | yolov5nu | yolov5su | yolov5mu | yolov5lu | yolov5xu |
| yolov8 | yolov8n | yolov8s | yolov8m | yolov8l | yolov8x |
| yolov11 | yolov11n | yolov11s | yolov11m | yolov11l | yolov11x |
</details>
<details> <summary>Segmention Checkpoints</summary>
| model | n | s | m | l | x |
|---|---|---|---|---|---|
| yolov8 | yolov8n | yolov8s | yolov8m | yolov8l | yolov8x |
| yolov11 | yolov11n | yolov11s | yolov11m | yolov11l | yolov11x |
</details>
How to use
You can download the code or add it from nuget.
dotnet add package IntptrMax.YoloSharp
Please add one of libtorch-cpu, libtorch-cuda-12.1, libtorch-cuda-12.1-win-x64 or libtorch-cuda-12.1-linux-x64 version 2.5.1.0 and OpenCvSharp4.runtime to execute.
You can use it with the code below:
Yolo Task
string preTrainedModelPath = @"..\..\..\Assets\PreTrainedModels\yolov8n-obb.bin"; // Pretrained model path.
string predictImagePath = @"..\..\..\Assets\TestImage\trucks.jpg";
Mat predictImage = Cv2.ImRead(predictImagePath);
// Create a Yolo config
Config config = new Config
{
DeviceType = DeviceType.CUDA,
ScalarType = ScalarType.Float16,
RootPath = @"..\..\..\Assets\DataSets\dotav1",
TrainDataPath = "train.txt",
ValDataPath = "val.txt",
YoloType = YoloType.Yolov8,
YoloSize = YoloSize.n,
TaskType = TaskType.Obb,
ImageProcessType = ImageProcessType.Mosiac,
ImageSize = 640,
BatchSize = 16,
NumberClass = 15,
PredictThreshold = 0.3f,
IouThreshold = 0.7f,
Workers = 4,
Epochs = 100,
};
// Create a yolo task.
YoloTask yoloTask = new YoloTask(config);
// Load pre-trained model. If you don't want to use pre-trained model, skip the step.
yoloTask.LoadModel(preTrainedModelPath, skipNcNotEqualLayers: true);
// Train model
yoloTask.Train();
// Predict image, if the model is not trained or loaded, it will use random weight to predict.
List<YoloResult> predictResult = yoloTask.ImagePredict(predictImage);
<br/>
Use yolov8n pre-trained model to detect.

Use yolov8n-seg pre-trained model to detect.

Use yolov8n-obb pre-trained model to detect.

Use yolov8n-pose pre-trained model to detect.

| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. |
-
net6.0
- Newtonsoft.Json (>= 13.0.4)
- OpenCvSharp4 (>= 4.11.0.20250507)
- TorchSharp (>= 0.105.2)
- TorchVision (>= 0.105.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.