Spaces:
Running
Running
File size: 715 Bytes
e07dafb | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | import torch
import os
def get_yolov5(confident_val):
"""Initialize YOLOv5 model with CPU optimizations"""
# Force CPU mode
os.environ['CUDA_VISIBLE_DEVICES'] = ''
torch.set_num_threads(1) # Limit to single thread for better CPU performance
# Load model with optimization flags
model = torch.hub.load('./yolov5', 'custom', path='./countmodel.pt', source='local', force_reload=False)
# Configure model settings
model.conf = confident_val # Confidence threshold
model.max_det = 4000 # Maximum detections
model.cpu() # Ensure CPU mode
# Enable inference optimizations
model.eval() # Set to evaluation mode
return model
|