mirror of
https://github.com/openmv/openmv.git
synced 2025-09-26 23:09:13 +08:00
Merge 87c25aa11c
into a19d832f1e
This commit is contained in:
commit
9e5d51181b
@ -107,20 +107,23 @@ class fomo_postprocess:
|
|||||||
# Get the class information
|
# Get the class information
|
||||||
bb_classes = np.argmax(bb[:, _FOMO_CLASSES:], axis=1) + _FOMO_CLASSES
|
bb_classes = np.argmax(bb[:, _FOMO_CLASSES:], axis=1) + _FOMO_CLASSES
|
||||||
|
|
||||||
|
# Compute the bounding box information
|
||||||
|
x_center = (bb_cols + 0.5) / ow
|
||||||
|
y_center = (bb_rows + 0.5) / oh
|
||||||
|
w_rel = np.full(len(bb_cols), self.w_scale / ow) * 0.5
|
||||||
|
h_rel = np.full(len(bb_rows), self.h_scale / oh) * 0.5
|
||||||
|
|
||||||
# Scale the bounding boxes to have enough integer precision for NMS
|
# Scale the bounding boxes to have enough integer precision for NMS
|
||||||
ib, ih, iw, ic = model.input_shape[0]
|
ib, ih, iw, ic = model.input_shape[0]
|
||||||
x_center = ((bb_cols + 0.5) / ow) * iw
|
xmin = (x_center - w_rel) * iw
|
||||||
y_center = ((bb_rows + 0.5) / oh) * ih
|
ymin = (y_center - h_rel) * ih
|
||||||
w_rel = np.full(len(bb_cols), self.w_scale / ow) * iw
|
xmax = (x_center + w_rel) * iw
|
||||||
h_rel = np.full(len(bb_rows), self.h_scale / oh) * ih
|
ymax = (y_center + h_rel) * ih
|
||||||
|
|
||||||
nms = NMS(iw, ih, inputs[0].roi)
|
nms = NMS(iw, ih, inputs[0].roi)
|
||||||
for i in range(bb.shape[0]):
|
for i in range(bb.shape[0]):
|
||||||
nms.add_bounding_box(x_center[i] - (w_rel[i] / 2),
|
nms.add_bounding_box(xmin[i], ymin[i], xmax[i], ymax[i], bb_scores[i], bb_classes[i])
|
||||||
y_center[i] - (h_rel[i] / 2),
|
|
||||||
x_center[i] + (w_rel[i] / 2),
|
|
||||||
y_center[i] + (h_rel[i] / 2),
|
|
||||||
bb_scores[i], bb_classes[i])
|
|
||||||
return nms.get_bounding_boxes(threshold=self.nms_threshold, sigma=self.nms_sigma)
|
return nms.get_bounding_boxes(threshold=self.nms_threshold, sigma=self.nms_sigma)
|
||||||
|
|
||||||
|
|
||||||
@ -159,8 +162,7 @@ class yolo_v2_postprocess:
|
|||||||
class_count = (oc // self.anchors_len) - _YOLO_V2_CLASSES
|
class_count = (oc // self.anchors_len) - _YOLO_V2_CLASSES
|
||||||
|
|
||||||
# Reshape the output to a 2D array
|
# Reshape the output to a 2D array
|
||||||
row_outputs = outputs[0].reshape((oh * ow * self.anchors_len,
|
row_outputs = outputs[0].reshape((oh * ow * self.anchors_len, _YOLO_V2_CLASSES + class_count))
|
||||||
_YOLO_V2_CLASSES + class_count))
|
|
||||||
|
|
||||||
# Threshold all the scores
|
# Threshold all the scores
|
||||||
score_indices = row_outputs[:, _YOLO_V2_SCORE]
|
score_indices = row_outputs[:, _YOLO_V2_SCORE]
|
||||||
@ -188,23 +190,20 @@ class yolo_v2_postprocess:
|
|||||||
# Compute the bounding box information
|
# Compute the bounding box information
|
||||||
x_center = (bb_cols + sigmoid(bb[:, _YOLO_V2_TX])) / ow
|
x_center = (bb_cols + sigmoid(bb[:, _YOLO_V2_TX])) / ow
|
||||||
y_center = (bb_rows + sigmoid(bb[:, _YOLO_V2_TY])) / oh
|
y_center = (bb_rows + sigmoid(bb[:, _YOLO_V2_TY])) / oh
|
||||||
w_rel = (bb_a_array[:, 0] * np.exp(bb[:, _YOLO_V2_TW])) / ow
|
w_rel = bb_a_array[:, 0] * np.exp(bb[:, _YOLO_V2_TW]) / ow * 0.5
|
||||||
h_rel = (bb_a_array[:, 1] * np.exp(bb[:, _YOLO_V2_TH])) / oh
|
h_rel = bb_a_array[:, 1] * np.exp(bb[:, _YOLO_V2_TH]) / oh * 0.5
|
||||||
|
|
||||||
# Scale the bounding boxes to have enough integer precision for NMS
|
# Scale the bounding boxes to have enough integer precision for NMS
|
||||||
ib, ih, iw, ic = model.input_shape[0]
|
ib, ih, iw, ic = model.input_shape[0]
|
||||||
x_center = x_center * iw
|
xmin = (x_center - w_rel) * iw
|
||||||
y_center = y_center * ih
|
ymin = (y_center - h_rel) * ih
|
||||||
w_rel = w_rel * iw
|
xmax = (x_center + w_rel) * iw
|
||||||
h_rel = h_rel * ih
|
ymax = (y_center + h_rel) * ih
|
||||||
|
|
||||||
nms = NMS(iw, ih, inputs[0].roi)
|
nms = NMS(iw, ih, inputs[0].roi)
|
||||||
for i in range(bb.shape[0]):
|
for i in range(bb.shape[0]):
|
||||||
nms.add_bounding_box(x_center[i] - (w_rel[i] / 2),
|
nms.add_bounding_box(xmin[i], ymin[i], xmax[i], ymax[i], bb_scores[i], bb_classes[i])
|
||||||
y_center[i] - (h_rel[i] / 2),
|
|
||||||
x_center[i] + (w_rel[i] / 2),
|
|
||||||
y_center[i] + (h_rel[i] / 2),
|
|
||||||
bb_scores[i], bb_classes[i])
|
|
||||||
return nms.get_bounding_boxes(threshold=self.nms_threshold, sigma=self.nms_sigma)
|
return nms.get_bounding_boxes(threshold=self.nms_threshold, sigma=self.nms_sigma)
|
||||||
|
|
||||||
|
|
||||||
@ -273,8 +272,8 @@ class yolo_v5_postprocess:
|
|||||||
|
|
||||||
nms = NMS(iw, ih, inputs[0].roi)
|
nms = NMS(iw, ih, inputs[0].roi)
|
||||||
for i in range(bb.shape[0]):
|
for i in range(bb.shape[0]):
|
||||||
nms.add_bounding_box(xmin[i], ymin[i], xmax[i], ymax[i],
|
nms.add_bounding_box(xmin[i], ymin[i], xmax[i], ymax[i], bb_scores[i], bb_classes[i])
|
||||||
bb_scores[i], bb_classes[i])
|
|
||||||
return nms.get_bounding_boxes(threshold=self.nms_threshold, sigma=self.nms_sigma)
|
return nms.get_bounding_boxes(threshold=self.nms_threshold, sigma=self.nms_sigma)
|
||||||
|
|
||||||
|
|
||||||
@ -297,28 +296,28 @@ class yolo_v8_postprocess:
|
|||||||
class_count = ow - _YOLO_V8_CLASSES
|
class_count = ow - _YOLO_V8_CLASSES
|
||||||
|
|
||||||
# Reshape the output to a 2D array
|
# Reshape the output to a 2D array
|
||||||
column_outputs = outputs[0].reshape((oh * (_YOLO_V8_CLASSES + class_count), oc))
|
row_outputs = outputs[0].reshape((oh * (_YOLO_V8_CLASSES + class_count), oc)).T
|
||||||
|
|
||||||
# Threshold all the scores
|
# Threshold all the scores
|
||||||
score_indices = column_outputs[_YOLO_V8_CLASSES:, :]
|
score_indices = row_outputs[:, _YOLO_V8_CLASSES:]
|
||||||
score_indices = threshold(score_indices, t, scale, find_max=True, find_max_axis=0)
|
score_indices = threshold(score_indices, t, scale, find_max=True, find_max_axis=1)
|
||||||
if not len(score_indices):
|
if not len(score_indices):
|
||||||
return _NO_DETECTION
|
return _NO_DETECTION
|
||||||
|
|
||||||
# Get the bounding boxes that have a valid score
|
# Get the bounding boxes that have a valid score
|
||||||
bb = dequantize(model, np.take(column_outputs, score_indices, axis=1))
|
bb = dequantize(model, np.take(row_outputs, score_indices, axis=0))
|
||||||
|
|
||||||
# Get the score information
|
# Get the score information
|
||||||
bb_scores = np.max(bb[_YOLO_V8_CLASSES:, :], axis=0)
|
bb_scores = np.max(bb[:, _YOLO_V8_CLASSES:], axis=1)
|
||||||
|
|
||||||
# Get the class information
|
# Get the class information
|
||||||
bb_classes = np.argmax(bb[_YOLO_V8_CLASSES:, :], axis=0)
|
bb_classes = np.argmax(bb[:, _YOLO_V8_CLASSES:], axis=1)
|
||||||
|
|
||||||
# Compute the bounding box information
|
# Compute the bounding box information
|
||||||
x_center = bb[_YOLO_V8_CX, :]
|
x_center = bb[:, _YOLO_V8_CX]
|
||||||
y_center = bb[_YOLO_V8_CY, :]
|
y_center = bb[:, _YOLO_V8_CY]
|
||||||
w_rel = bb[_YOLO_V8_CW, :] * 0.5
|
w_rel = bb[:, _YOLO_V8_CW] * 0.5
|
||||||
h_rel = bb[_YOLO_V8_CH, :] * 0.5
|
h_rel = bb[:, _YOLO_V8_CH] * 0.5
|
||||||
|
|
||||||
# Scale the bounding boxes to have enough integer precision for NMS
|
# Scale the bounding boxes to have enough integer precision for NMS
|
||||||
ib, ih, iw, ic = model.input_shape[0]
|
ib, ih, iw, ic = model.input_shape[0]
|
||||||
@ -328,9 +327,9 @@ class yolo_v8_postprocess:
|
|||||||
ymax = (y_center + h_rel) * ih
|
ymax = (y_center + h_rel) * ih
|
||||||
|
|
||||||
nms = NMS(iw, ih, inputs[0].roi)
|
nms = NMS(iw, ih, inputs[0].roi)
|
||||||
for i in range(bb.shape[1]):
|
for i in range(bb.shape[0]):
|
||||||
nms.add_bounding_box(xmin[i], ymin[i], xmax[i], ymax[i],
|
nms.add_bounding_box(xmin[i], ymin[i], xmax[i], ymax[i], bb_scores[i], bb_classes[i])
|
||||||
bb_scores[i], bb_classes[i])
|
|
||||||
return nms.get_bounding_boxes(threshold=self.nms_threshold, sigma=self.nms_sigma)
|
return nms.get_bounding_boxes(threshold=self.nms_threshold, sigma=self.nms_sigma)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user