DAQ: MlBox.py added debug statements when errors occur and fixed bug in check_box_relation and box_relation
This commit is contained in:
@@ -7,7 +7,7 @@ import requests
|
||||
from aaredaqlib.models import MLBoxModel, MLOutputModel, MLBoxType, BoundingBoxModel
|
||||
from aaredaqlib.logger_config import setup_logger
|
||||
|
||||
logger=setup_logger(__name__, '/tmp/mxlogs')
|
||||
logger=setup_logger("aareDAQ")
|
||||
|
||||
class MlBox:
|
||||
|
||||
@@ -30,9 +30,12 @@ class MlBox:
|
||||
logger.debug(response.text)
|
||||
return response.json()
|
||||
|
||||
def check_box_relation(self, box0, box1):
|
||||
x10, y10, x20, y20, _ = box0
|
||||
x11, y11, x21, y21, _ = box1
|
||||
def check_box_relation(self, box0: MLBoxModel, box1: MLBoxModel):
|
||||
# Extract (x1,y1,x2,y2) from MLBoxModel/BoundingBoxModel
|
||||
if not box0 or not box0.box or not box1 or not box1.box:
|
||||
raise ValueError("Invalid boxes passed to check_box_relation")
|
||||
x10, y10, x20, y20 = box0.box.top_x, box0.box.top_y, box0.box.bottom_x, box0.box.bottom_y
|
||||
x11, y11, x21, y21 = box1.box.top_x, box1.box.top_y, box1.box.bottom_x, box1.box.bottom_y
|
||||
left, top, overlap_x, overlap_y = False, False, False, False
|
||||
|
||||
# Compute centers for robustness
|
||||
@@ -55,7 +58,7 @@ class MlBox:
|
||||
else:
|
||||
overlap_y = True
|
||||
|
||||
return {"left":left, "top":top, "overlap_x":overlap_x, "overlap_y":overlap_y}
|
||||
return {"left": left, "top": top, "overlap_x": overlap_x, "overlap_y": overlap_y}
|
||||
|
||||
def box_relation(self, boxes: MLOutputModel, classes:list[str]|None = None):
|
||||
pin: MLBoxModel | None = boxes.get_best_for_class(MLBoxType.Pin)
|
||||
@@ -65,8 +68,10 @@ class MlBox:
|
||||
|
||||
box_relative_to_pin: dict[str, bool] = {}
|
||||
for box_type in classes:
|
||||
if boxes[box_type]:
|
||||
box_relative_to_pin = self.check_box_relation(pin, boxes[box_type])
|
||||
# Ensure the entry exists and is an MLBoxModel
|
||||
model = boxes.get(box_type) if hasattr(boxes, "get") else boxes.boxes.get(box_type)
|
||||
if model:
|
||||
box_relative_to_pin = self.check_box_relation(pin, model)
|
||||
|
||||
return box_relative_to_pin
|
||||
|
||||
@@ -199,11 +204,15 @@ class MlBox:
|
||||
response = self.get_response(image)
|
||||
results = response.get("results") if isinstance(response, dict) else None
|
||||
if not results:
|
||||
logger.debug(f"No results from ML model: {results}")
|
||||
return None
|
||||
best = self._best_by_class(results)
|
||||
if not best:
|
||||
logger.debug(f"No best predictions from ML model: {best}")
|
||||
return None
|
||||
logger.debug(f"Best predictions from ML model: {best}")
|
||||
self._filter_predictions(best, overlap_with_pin=overlap_with_pin, confidence_min=confidence_min)
|
||||
logger.debug(f"Filtered best predictions from ML model: {best}")
|
||||
return best
|
||||
|
||||
def predict_all(self, image,
|
||||
|
||||
Reference in New Issue
Block a user