Closed danielroson closed 5 days ago
👋 Hello @danielroson, thank you for your interest in Ultralytics 🚀! We recommend checking out the Docs for more information, where many Python and CLI usage examples are available to assist with various workflows.
If this is a 🐛 Bug Report or unexpected behavior, please share a minimum reproducible example so that we can better understand and address your issue. This includes the exact code snippet used and the steps to replicate the behavior you are observing.
For custom configuration-related ❓ Questions like this, providing more context about your environment (e.g., OS, version of Python, PyTorch, and ultralytics package) and any specific error logs or messages would help us diagnose the issue more effectively. If you haven't already, ensure you're following Tips for Best Training Results for optimal performance.
First, please ensure you're running the latest version of Ultralytics, as updates often include fixes and optimizations. Upgrade with the following command:
pip install -U ultralytics
YOLO models can be run in a variety of environments. Ensure you're testing in one of our verified setups to see if this resolves the issue:
Additionally, specifying the environment.yml
file allows you to recreate our exact dependency setup.
To verify the integrity of your setup, you can check the status of our CI tests, which run daily to validate functionality against various tasks and modes:
These tests ensure compatibility on macOS, Windows, and Ubuntu platforms with all features.
We appreciate your contribution to the community by asking this question! 😊 Please note that this is an automated response, and an Ultralytics engineer will follow up with you shortly for further assistance.
Sorry, I found the solution
Great to hear you found a solution! For others seeking to limit YOLOv11 to a single CPU thread, you can set environment variables before importing torch/ultralytics:
import os
os.environ["OMP_NUM_THREADS"] = "1"
os.environ["MKL_NUM_THREADS"] = "1"
import torch
torch.set_num_threads(1)
from ultralytics import YOLO
model = YOLO('yolo11n.pt')
results = model(source, device='cpu')
This combination of environment variables and thread limits helps restrict CPU parallelism. For more details, refer to PyTorch CPU parallelism docs.
Search before asking
Question
How to limit yolo11 ultralytics to use single thread (CPU) during prediction process.
I have a project using image classifications that I need to limit the use of server resources (threads).
I tried: results = model(source, device='cpu', workers=1)
or:
export OPENBLAS_NUM_THREADS=1 export NUMEXPR_NUM_THREADS=1 export VECLIB_MAXIMUM_THREADS=1 export NUM_THREADS=1
or:
import torch torch.set_num_threads(1) torch.set_num_interop_threads(1)
For the test, the application loads a class that does the inference and another that keeps sending the same image and collecting the result:
See below the CPU usage during the test:
Additional
No response