|
@@ -12,9 +12,9 @@ from watermark_verify.tools import parse_qrcode_label_file
|
|
|
from watermark_verify.tools.evaluate_tool import calculate_ciou
|
|
|
|
|
|
|
|
|
-class ClassificationProcess(BlackBoxWatermarkProcessDefine):
|
|
|
+class DetectionProcess(BlackBoxWatermarkProcessDefine):
|
|
|
def __init__(self, model_filename):
|
|
|
- super(ClassificationProcess, self).__init__(model_filename)
|
|
|
+ super(DetectionProcess, self).__init__(model_filename)
|
|
|
|
|
|
def process(self) -> bool:
|
|
|
"""
|
|
@@ -89,18 +89,7 @@ class ClassificationProcess(BlackBoxWatermarkProcessDefine):
|
|
|
|
|
|
ort_inputs = {session.get_inputs()[0].name: img[None, :, :, :]}
|
|
|
output = session.run(None, ort_inputs)
|
|
|
- predictions = postprocess(output[0], input_shape)[0]
|
|
|
-
|
|
|
- boxes = predictions[:, :4]
|
|
|
- scores = predictions[:, 4:5] * predictions[:, 5:]
|
|
|
-
|
|
|
- boxes_xyxy = np.ones_like(boxes)
|
|
|
- boxes_xyxy[:, 0] = boxes[:, 0] - boxes[:, 2] / 2.
|
|
|
- boxes_xyxy[:, 1] = boxes[:, 1] - boxes[:, 3] / 2.
|
|
|
- boxes_xyxy[:, 2] = boxes[:, 0] + boxes[:, 2] / 2.
|
|
|
- boxes_xyxy[:, 3] = boxes[:, 1] + boxes[:, 3] / 2.
|
|
|
- boxes_xyxy /= ratio
|
|
|
- dets = multiclass_nms(boxes_xyxy, scores, nms_thr=0.45, score_thr=0.1)
|
|
|
+ dets = postprocess(output[0], input_shape, ratio)[0]
|
|
|
if dets is not None:
|
|
|
detect_result = detect_watermark(dets, watermark_box)
|
|
|
return detect_result
|
|
@@ -108,9 +97,10 @@ class ClassificationProcess(BlackBoxWatermarkProcessDefine):
|
|
|
return False
|
|
|
|
|
|
|
|
|
-def postprocess(outputs, img_size, p6=False):
|
|
|
+def postprocess(outputs, img_size, ratio, p6=False):
|
|
|
grids = []
|
|
|
expanded_strides = []
|
|
|
+ outputs = outputs[0]
|
|
|
strides = [8, 16, 32] if not p6 else [8, 16, 32, 64]
|
|
|
|
|
|
hsizes = [img_size[0] // stride for stride in strides]
|
|
@@ -128,7 +118,18 @@ def postprocess(outputs, img_size, p6=False):
|
|
|
outputs[..., :2] = (outputs[..., :2] + grids) * expanded_strides
|
|
|
outputs[..., 2:4] = np.exp(outputs[..., 2:4]) * expanded_strides
|
|
|
|
|
|
- return outputs
|
|
|
+ boxes = outputs[:, :4]
|
|
|
+ scores = outputs[:, 4:5] * outputs[:, 5:]
|
|
|
+
|
|
|
+ boxes_xyxy = np.ones_like(boxes)
|
|
|
+ boxes_xyxy[:, 0] = boxes[:, 0] - boxes[:, 2] / 2.
|
|
|
+ boxes_xyxy[:, 1] = boxes[:, 1] - boxes[:, 3] / 2.
|
|
|
+ boxes_xyxy[:, 2] = boxes[:, 0] + boxes[:, 2] / 2.
|
|
|
+ boxes_xyxy[:, 3] = boxes[:, 1] + boxes[:, 3] / 2.
|
|
|
+ boxes_xyxy /= ratio
|
|
|
+ dets = multiclass_nms(boxes_xyxy, scores, nms_thr=0.45, score_thr=0.1)
|
|
|
+
|
|
|
+ return dets
|
|
|
|
|
|
|
|
|
def nms(boxes, scores, nms_thr):
|