Update handler.py
Browse files- handler.py +9 -7
handler.py
CHANGED
|
@@ -8,13 +8,13 @@ from io import BytesIO
|
|
| 8 |
|
| 9 |
class EndpointHandler():
|
| 10 |
def __init__(self, path=""):
|
| 11 |
-
hf_hub_download(repo_id="Drazcat-AI/flejes", filename="yolov8_flejes/runs/detect/train/weights/
|
| 12 |
-
self.model = YOLO(hf_hub_download(repo_id="Drazcat-AI/flejes", filename="yolov8_flejes/runs/detect/train/weights/
|
| 13 |
|
| 14 |
def predict_objects(self, image_path):
|
| 15 |
-
|
| 16 |
#results = self.model(image_path, imgsz=800)
|
| 17 |
-
results = self.model(image_path)
|
| 18 |
predictions = []
|
| 19 |
for box in results[0].boxes:
|
| 20 |
class_id = results[0].names[box.cls[0].item()]
|
|
@@ -44,9 +44,11 @@ class EndpointHandler():
|
|
| 44 |
image_path = event["inputs"]
|
| 45 |
|
| 46 |
try:
|
| 47 |
-
|
| 48 |
-
#
|
| 49 |
-
image = Image.open(BytesIO(data))
|
|
|
|
|
|
|
| 50 |
predictions = self.predict_objects(image)
|
| 51 |
return {
|
| 52 |
"statusCode": 200,
|
|
|
|
| 8 |
|
| 9 |
class EndpointHandler():
|
| 10 |
def __init__(self, path=""):
|
| 11 |
+
hf_hub_download(repo_id="Drazcat-AI/flejes", filename="yolov8_flejes/runs/detect/train/weights/best.pt")
|
| 12 |
+
self.model = YOLO(hf_hub_download(repo_id="Drazcat-AI/flejes", filename="yolov8_flejes/runs/detect/train/weights/best.pt", local_files_only=True))
|
| 13 |
|
| 14 |
def predict_objects(self, image_path):
|
| 15 |
+
results = self.model(image_path, imgsz=1280)
|
| 16 |
#results = self.model(image_path, imgsz=800)
|
| 17 |
+
#results = self.model(image_path)
|
| 18 |
predictions = []
|
| 19 |
for box in results[0].boxes:
|
| 20 |
class_id = results[0].names[box.cls[0].item()]
|
|
|
|
| 44 |
image_path = event["inputs"]
|
| 45 |
|
| 46 |
try:
|
| 47 |
+
#url image
|
| 48 |
+
#data=urlopen(image_path).read()
|
| 49 |
+
#image = Image.open(BytesIO(data))
|
| 50 |
+
#bytes image
|
| 51 |
+
image=image_path
|
| 52 |
predictions = self.predict_objects(image)
|
| 53 |
return {
|
| 54 |
"statusCode": 200,
|