Spaces:
Running
Running
Download model.py from npisb/pipecountapp: direct link, hf CLI and curl.
- Browser
- Download file 715 Bytes
-
https://huggingface.co/spaces/npisb/pipecountapp/resolve/refs%2Fpr%2F2/model.py
- Command line
-
hf download hf://spaces/npisb/pipecountapp@refs/pr/2/model.py
-
curl -L -o model.py https://huggingface.co/spaces/npisb/pipecountapp/resolve/refs%2Fpr%2F2/model.py
715 Bytes
| 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 | |