Update handler.py
Browse files- handler.py +5 -1
handler.py
CHANGED
|
@@ -12,7 +12,7 @@ class EndpointHandler():
|
|
| 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, image_size_m):
|
| 15 |
-
results = self.model(image_path)
|
| 16 |
predictions = []
|
| 17 |
for box in results[0].boxes:
|
| 18 |
class_id = results[0].names[box.cls[0].item()]
|
|
@@ -45,13 +45,17 @@ class EndpointHandler():
|
|
| 45 |
with urllib.request.urlopen(image_path) as response:
|
| 46 |
image_content = np.asarray(bytearray(response.read()), dtype=np.uint8)
|
| 47 |
image = cv2.imdecode(image_content, cv2.IMREAD_COLOR)
|
|
|
|
| 48 |
image_size = image.shape
|
| 49 |
if image.shape[0]>image.shape[0]:
|
| 50 |
x, y = 1280, 960
|
| 51 |
else:
|
| 52 |
y, x = 1280, 960
|
| 53 |
image = cv2.resize(image, (x, y))
|
|
|
|
| 54 |
predictions = self.predict_objects(image, [image_size[0]/x,image_size[1]/y])
|
|
|
|
|
|
|
| 55 |
return {
|
| 56 |
"statusCode": 200,
|
| 57 |
"body": json.dumps(predictions),
|
|
|
|
| 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, image_size_m):
|
| 15 |
+
results = self.model(image_path, imgsz=[1280, 960])
|
| 16 |
predictions = []
|
| 17 |
for box in results[0].boxes:
|
| 18 |
class_id = results[0].names[box.cls[0].item()]
|
|
|
|
| 45 |
with urllib.request.urlopen(image_path) as response:
|
| 46 |
image_content = np.asarray(bytearray(response.read()), dtype=np.uint8)
|
| 47 |
image = cv2.imdecode(image_content, cv2.IMREAD_COLOR)
|
| 48 |
+
"""
|
| 49 |
image_size = image.shape
|
| 50 |
if image.shape[0]>image.shape[0]:
|
| 51 |
x, y = 1280, 960
|
| 52 |
else:
|
| 53 |
y, x = 1280, 960
|
| 54 |
image = cv2.resize(image, (x, y))
|
| 55 |
+
|
| 56 |
predictions = self.predict_objects(image, [image_size[0]/x,image_size[1]/y])
|
| 57 |
+
"""
|
| 58 |
+
predictions = self.predict_objects(image, (1,1))
|
| 59 |
return {
|
| 60 |
"statusCode": 200,
|
| 61 |
"body": json.dumps(predictions),
|