Skip to content

Commit

Permalink
Added separate set_logger function for DetectorBase and Detector Plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
jasmeet0915 committed Mar 3, 2024
1 parent 777c074 commit 5cecae8
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
6 changes: 4 additions & 2 deletions object_detection/object_detection/DetectorBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@

class DetectorBase(ABC):

def __init__(self, logger) -> None:
self.logger = logger
def __init__(self) -> None:
self.predictions = []

def set_logger(self, logger) -> None:
self.logger = logger

def create_predictions_list(self, class_ids, confidences, boxes):
self.predictions = []
for i in range(len(class_ids)):
Expand Down
7 changes: 2 additions & 5 deletions object_detection/object_detection/Detectors/RetinaNet.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,8 @@

class RetinaNet(DetectorBase):

def __init__(self, logger):
super().__init__(logger)

# Create a logger instance
self.logger = super().get_logger()
def __init__(self):
super().__init__()

def build_model(self, model_dir_path, weight_file_name):
model_path = os.path.join(model_dir_path, weight_file_name)
Expand Down
7 changes: 2 additions & 5 deletions object_detection/object_detection/Detectors/YOLOv5.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,10 @@

class YOLOv5(DetectorBase):

def __init__(self, logger, conf_threshold=0.7):
super().__init__(logger)
def __init__(self, conf_threshold=0.7):
super().__init__()
self.conf_threshold = conf_threshold

# Create a logger instance
self.logger = super().get_logger()

def build_model(self, model_dir_path, weight_file_name):
try:
model_path = os.path.join(model_dir_path, weight_file_name)
Expand Down
4 changes: 2 additions & 2 deletions object_detection/object_detection/Detectors/YOLOv8.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@

class YOLOv8(DetectorBase):

def __init__(self, logger):
def __init__(self):

super().__init__(logger)
super().__init__()

def build_model(self, model_dir_path, weight_file_name):
try:
Expand Down
8 changes: 6 additions & 2 deletions object_detection/object_detection/ObjectDetection.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def __init__(self):
self.available_detectors = []

# Create a logger instance
self.logger = super().get_logger()
self.logger = self.get_logger()

# Declare parameters with default values
self.declare_parameters(
Expand Down Expand Up @@ -111,8 +111,12 @@ def load_detector(self):
detector_mod = importlib.import_module(".Detectors." + self.detector_type,
"object_detection")
detector_class = getattr(detector_mod, self.detector_type)
self.detector = detector_class(self.logger)
self.detector = detector_class()

# Set the logger for the detector plugins
self.detector.set_logger(self.logger)

# Load the model and the classes file for the detector plugin
self.detector.build_model(self.model_dir_path, self.weight_file_name)
self.detector.load_classes(self.model_dir_path)

Expand Down

0 comments on commit 5cecae8

Please sign in to comment.