-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhanced ObjectDetector with batch processing and error handling. Imp…
…roved model_training with adaptive learning rates and early stopping.
- Loading branch information
1 parent
49f45b4
commit 132f069
Showing
2 changed files
with
51 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,24 @@ | ||
from .object_detection_interface import ObjectDetectionInterface, preprocess_image | ||
import numpy as np | ||
from typing import List, Union | ||
|
||
class ObjectDetector: | ||
def __init__(self): | ||
self.detector = ObjectDetectionInterface() | ||
|
||
def detect_objects(self, image): | ||
preprocessed_image = preprocess_image(image) | ||
return self.detector.detect(preprocessed_image) | ||
def detect_objects(self, images: Union[np.ndarray, List[np.ndarray]]): | ||
try: | ||
if isinstance(images, np.ndarray): | ||
images = [images] | ||
|
||
preprocessed_images = [preprocess_image(img) for img in images] | ||
batch_results = self.detector.detect_batch(preprocessed_images) | ||
|
||
return [self._post_process(result) for result in batch_results] | ||
except Exception as e: | ||
print(f"Error in object detection: {str(e)}") | ||
return [] | ||
|
||
def _post_process(self, detection_result): | ||
# Implement post-processing logic here (e.g., non-max suppression, filtering) | ||
return detection_result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters