NaveenKumar5 commited on
Commit
3c661d9
·
verified ·
1 Parent(s): f399cd0

Update inference.py

Browse files
Files changed (1) hide show
  1. inference.py +10 -14
inference.py CHANGED
@@ -1,17 +1,13 @@
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()
 
 
1
  from roboflow import Roboflow
2
+ from PIL import Image
3
+ import numpy as np
4
 
5
+ # Load Roboflow model
6
+ rf = Roboflow(api_key="rSfidObyvZ1BYV7yOQrN")
7
+ project = rf.workspace("naveen-kumar-9emxl").project("my-first-project-icheu")
8
+ model = project.version(1).model
9
 
10
+ def predict(image):
11
+ image = np.array(image)
12
+ prediction = model.predict(image).plot()
13
+ return Image.fromarray(prediction)