dotnet / dotnet/machinelearning

ASP.NET vs ML.Net ObjectDetection

Open
#7,219 10 comments 0 reactions 0 assignees View on GitHub
area-TorchSharp untriaged
Dominant language
C#
Stars
9.4k
Forks
2k
Avg merge
2d 20h
Merged PRs (30d)
11

Description

**System Information (please complete the following information):**
- OS & Version: Docker linux
- ML.NET Version: latest
- .NET Version: 8.0

**Describe the bug**
Hi all,

I'm currently having an issue with object detection in the docker container by using TorchSharp-Cpu. The first object detection is going fine by having around 2 GB in use, but after more like 100 the RAM usage is going up to 4GB and more.
And the worst part of it is that this is running out of memory after a while.
Looking at the process after the usage was done, there was no decrease in memory usage happening.

The model is created by images up to 9MB PNGs but resized in the model to only 250 by 250.

I was already multiple times checking the using statements and all IDisposable objects.

**To Reproduce**
Steps to reproduce the behavior:
1. Set Up ASP.Web API
2. Add an object detection Model => train it etc.
3. Add a controller to use the model
4. Provide an upload function with IFormFile
5. Add using on opening the IFormFileStream
6. Add using for the ModelInput
7. Add a result around the prediction, store the result of precision in that, and close or make a using the output image.
8. Make sure all using's are there and all streams are going to be closed.
9. Optional (Add a lock statement around prediction to make it anytime single-threaded)

**Expected behavior**
RAM usage for single-threaded usage should go not over 2.5 GB or come down after usage. Dot. Memory on Windows was only showing that there is a lot of unmanaged Memory in use (streams).

**Screenshots, Code, Sample Projects**
![image](https://github.com/user-attachments/assets/df8408cc-1c08-427c-9280-5a40dfb90c6d)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.