Skip to content

Commit

Permalink
Merge pull request #184 from PUTvision/yolo11_obb
Browse files Browse the repository at this point in the history
Support confirmation for ULTRALYTICS YOLOv10 and YOLO11; support for ULTRALYTICS OBB models
  • Loading branch information
przemyslaw-aszkowski authored Oct 3, 2024
2 parents be6d8d6 + 5102f28 commit 3d68a83
Show file tree
Hide file tree
Showing 10 changed files with 383 additions and 35 deletions.
1 change: 1 addition & 0 deletions docs/source/creators/creators_add_metadata_to_model.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Availeble detector types:
- :code:`YOLO_v9`
- :code:`YOLO_Ultralytics`
- :code:`YOLO_Ultralytics_segmentation`
- :code:`YOLO_Ultralytics_obb`

=======
Example
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class DetectorType(enum.Enum):
YOLO_v9 = 'YOLO_v9'
YOLO_ULTRALYTICS = 'YOLO_Ultralytics'
YOLO_ULTRALYTICS_SEGMENTATION = 'YOLO_Ultralytics_segmentation'
YOLO_ULTRALYTICS_OBB = 'YOLO_Ultralytics_obb'

def get_parameters(self):
if self == DetectorType.YOLO_v5_v7_DEFAULT:
Expand All @@ -36,7 +37,7 @@ def get_parameters(self):
has_inverted_output_shape=True,
skipped_objectness_probability=True,
)
elif self == DetectorType.YOLO_ULTRALYTICS or self == DetectorType.YOLO_ULTRALYTICS_SEGMENTATION:
elif self == DetectorType.YOLO_ULTRALYTICS or self == DetectorType.YOLO_ULTRALYTICS_SEGMENTATION or self == DetectorType.YOLO_ULTRALYTICS_OBB:
return DetectorTypeParameters(
has_inverted_output_shape=True,
skipped_objectness_probability=True,
Expand Down
2 changes: 1 addition & 1 deletion src/deepness/metadata.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
name=Deepness: Deep Neural Remote Sensing
qgisMinimumVersion=3.22
description=Inference of deep neural network models (ONNX) for segmentation, detection and regression
version=0.6.3
version=0.6.4
author=PUT Vision
[email protected]

Expand Down
14 changes: 10 additions & 4 deletions src/deepness/processing/map_processor/map_processor_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from deepness.processing.map_processor.utils.ckdtree import cKDTree
from deepness.processing.models.detector import Detection, Detector
from deepness.processing.tile_params import TileParams
from deepness.processing.models.detector import DetectorType


class MapProcessorDetection(MapProcessorWithModel):
Expand Down Expand Up @@ -49,8 +50,10 @@ def _run(self) -> MapProcessingResult:
bounding_boxes_in_tile_batched = self._process_tile(tile_img_batched, tile_params_batched)
all_bounding_boxes += [d for det in bounding_boxes_in_tile_batched for d in det]

with_rot = self.detection_parameters.detector_type == DetectorType.YOLO_ULTRALYTICS_OBB

if len(all_bounding_boxes) > 0:
all_bounding_boxes_nms = self.remove_overlaping_detections(all_bounding_boxes, iou_threshold=self.detection_parameters.iou_threshold)
all_bounding_boxes_nms = self.remove_overlaping_detections(all_bounding_boxes, iou_threshold=self.detection_parameters.iou_threshold, with_rot=with_rot)
all_bounding_boxes_restricted = self.limit_bounding_boxes_to_processed_area(all_bounding_boxes_nms)
else:
all_bounding_boxes_restricted = []
Expand Down Expand Up @@ -197,17 +200,20 @@ def add_to_gui():
return add_to_gui

@staticmethod
def remove_overlaping_detections(bounding_boxes: List[Detection], iou_threshold: float) -> List[Detection]:
def remove_overlaping_detections(bounding_boxes: List[Detection], iou_threshold: float, with_rot: bool = False) -> List[Detection]:
bboxes = []
probs = []
for det in bounding_boxes:
bboxes.append(det.get_bbox_xyxy())
if with_rot:
bboxes.append(det.get_bbox_xyxy_rot())
else:
bboxes.append(det.get_bbox_xyxy())
probs.append(det.conf)

bboxes = np.array(bboxes)
probs = np.array(probs)

pick_ids = Detector.non_max_suppression_fast(bboxes, probs, iou_threshold)
pick_ids = Detector.non_max_suppression_fast(boxes=bboxes, probs=probs, iou_threshold=iou_threshold, with_rot=with_rot)

filtered_bounding_boxes = [x for i, x in enumerate(bounding_boxes) if i in pick_ids]
filtered_bounding_boxes = sorted(filtered_bounding_boxes, reverse=True)
Expand Down
Loading

0 comments on commit 3d68a83

Please sign in to comment.