NaveenKumar5 commited on
Commit
4026e79
·
verified ·
1 Parent(s): fae8280

Create inference.py

Browse files
Files changed (1) hide show
  1. inference.py +17 -0
inference.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from roboflow import Roboflow
3
+ from pathlib import Path
4
+
5
+ def run_detection(image_path):
6
+ rf = Roboflow(api_key="rSfidObyvZ1BYV7yOQrN")
7
+ project = rf.workspace("naveen-kumar-9emxl").project("my-first-project-icheu")
8
+ dataset = project.version(1).download("yolov5")
9
+
10
+ model_path = "runs/train/exp/weights/best.pt"
11
+ if not Path(model_path).exists():
12
+ print("Trained model not found.")
13
+ return
14
+
15
+ model = torch.hub.load('yolov5', 'custom', path=model_path, source='local')
16
+ results = model(image_path)
17
+ results.show()