I am using yolo5. I want to estimate how much CPU utilization does yolo take to process a certain image. how can I do that?
I tried to use P-Sutil to calculate the CPU utilization however I can not get how much cpu utilization for each image it took
here is my code
# !pip install -U ultralytics
import torch
import time
import psutil
from keras.datasets import cifar10
# Load YOLOv5 model
# model = torch.hub.load('ultralytics/yolov5', 'yolov5s', pretrained=True)
# Load CIFAR-10 dataset and select 10 images
(_, _), (x_test, _) = cifar10.load_data()
x_test_subset = x_test[:10] # Selecting first 10 images from the test set
# Loop through images
for i, img in enumerate(x_test_subset):
# Measure CPU time before YOLOv5 inference
start_cpu = psutil.cpu_times().user + psutil.cpu_times().system
# Convert image to PIL format and perform YOLOv5 inference
start_time = time.time()
results = model("/content/yolo.jpg", size=640) # You can adjust the size as needed
end_time = time.time()
# Measure CPU time after YOLOv5 inference
end_cpu = psutil.cpu_times().user + psutil.cpu_times().system
# Calculate CPU utilization for YOLOv5 inference
cpu_utilization_percentage = ((end_cpu - start_cpu) / psutil.cpu_count()) / (end_time - start_time) * 100
# Count objects detected
num_objects = len(results.xyxy[0])
# Print results for the current image
print("Image {}: Objects detected: {} - YOLO CPU utilization (%): {:.2f}".format(i+1, num_objects, cpu_utilization_percentage))
`