remove log messages. detect invalid output tensor count

This commit is contained in:
Dan Brown 2025-12-02 15:33:11 +01:00
parent d686b303ed
commit 1664b2f3bb

View File

@ -77,12 +77,10 @@ class EdgeTpuTfl(DetectionApi):
model_type = detector_config.model.model_type model_type = detector_config.model.model_type
self.model_requires_int8 = self.tensor_input_details[0]["dtype"] == np.int8 self.model_requires_int8 = self.tensor_input_details[0]["dtype"] == np.int8
if self.model_requires_int8:
logger.info("Detection model requires int8 format input")
if model_type == ModelTypeEnum.yologeneric if model_type == ModelTypeEnum.yologeneric
logger.info( logger.debug(
f"Preparing YOLO postprocessing for {len(self.tensor_output_details)}-tensor output" f"Using YOLO postprocessing for {len(self.tensor_output_details)}-tensor output"
) )
if len(self.tensor_output_details) > 1: # expecting 2 or 3 if len(self.tensor_output_details) > 1: # expecting 2 or 3
self.reg_max = 16 # = 64 dfl_channels // 4 # YOLO standard self.reg_max = 16 # = 64 dfl_channels // 4 # YOLO standard
@ -121,6 +119,7 @@ class EdgeTpuTfl(DetectionApi):
else 1 else 1
) # 0 is default guess ) # 0 is default guess
output_boxes_index = 1 if (output_boxes_index == 0) else 0 output_boxes_index = 1 if (output_boxes_index == 0) else 0
scores_details = self.tensor_output_details[output_classes_index] scores_details = self.tensor_output_details[output_classes_index]
classes_count = scores_details["shape"][2] classes_count = scores_details["shape"][2]
self.scores_tensor_index = scores_details["index"] self.scores_tensor_index = scores_details["index"]
@ -141,16 +140,13 @@ class EdgeTpuTfl(DetectionApi):
boxes_details = self.tensor_output_details[output_boxes_index] boxes_details = self.tensor_output_details[output_boxes_index]
self.boxes_tensor_index = boxes_details["index"] self.boxes_tensor_index = boxes_details["index"]
self.boxes_scale, self.boxes_zero_point = boxes_details["quantization"] self.boxes_scale, self.boxes_zero_point = boxes_details["quantization"]
logger.info(
f"Using tensor index {output_boxes_index} for boxes(DFL), {output_classes_index} for {classes_count} class scores"
)
else: else:
if model_type not in [ModelTypeEnum.ssd, None]: if model_type not in [ModelTypeEnum.ssd, None]:
logger.warning( logger.warning(
f"Unsupported model_type '{model_type}' for EdgeTPU detector, falling back to SSD" f"Unsupported model_type '{model_type}' for EdgeTPU detector, falling back to SSD"
) )
logger.info("Using SSD preprocessing/postprocessing") logger.debug("Using SSD preprocessing/postprocessing")
# SSD model indices (4 outputs: boxes, class_ids, scores, count) # SSD model indices (4 outputs: boxes, class_ids, scores, count)
for x in self.tensor_output_details: for x in self.tensor_output_details:
@ -215,7 +211,8 @@ class EdgeTpuTfl(DetectionApi):
self.interpreter.invoke() self.interpreter.invoke()
if model_type == ModelTypeEnum.yologeneric if model_type == ModelTypeEnum.yologeneric
if len(self.tensor_output_details) == 1: output_tensor_count = len(self.tensor_output_details)
if output_tensor_count == 1:
# Single-tensor YOLO model # Single-tensor YOLO model
# model output is (1, NC+4, 2100) for 320x320 image size # model output is (1, NC+4, 2100) for 320x320 image size
# boxes as xywh (normalized to [0,1]) # boxes as xywh (normalized to [0,1])
@ -234,7 +231,7 @@ class EdgeTpuTfl(DetectionApi):
return post_process_yolo(outputs, self.model_width, self.model_height) return post_process_yolo(outputs, self.model_width, self.model_height)
else: elif output_tensor_count in [2,3]:
# Multi-tensor YOLO model with (non-standard B(H*W)C output format). # Multi-tensor YOLO model with (non-standard B(H*W)C output format).
# (the comments indicate the shape of tensors, # (the comments indicate the shape of tensors,
# using "2100" as the anchor count (for image size of 320x320), # using "2100" as the anchor count (for image size of 320x320),
@ -349,6 +346,12 @@ class EdgeTpuTfl(DetectionApi):
detections[:num_detections, 5] = final_boxes[:, 2] / self.model_width detections[:num_detections, 5] = final_boxes[:, 2] / self.model_width
return detections return detections
else:
logger.error(
f"Invalid count of output tensors in YOLO model. Found {output_tensor_count}, expecting 1/2/3."
)
raise
else: else:
# Default SSD model # Default SSD model
self.determine_indexes_for_non_yolo_models() self.determine_indexes_for_non_yolo_models()
@ -369,7 +372,7 @@ class EdgeTpuTfl(DetectionApi):
if scores[i] < self.min_score: if scores[i] < self.min_score:
break break
if i == self.max_detections: if i == self.max_detections:
logger.info(f"Too many detections ({count})!") logger.debug(f"Too many detections ({count})!")
break break
detections[i] = [ detections[i] = [
class_ids[i], class_ids[i],