Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion detector/docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fi
# ========================== BUILD CONFIGURATION / IMAGE SELECTION =======================

SEMANTIC_VERSION=0.1.13
NODE_LIB_VERSION=0.17.0
NODE_LIB_VERSION=0.17.1
build_args=" --build-arg NODE_LIB_VERSION=$NODE_LIB_VERSION"

if [ -f /etc/nv_tegra_release ] # Check if we are on a Jetson device
Expand Down
23 changes: 14 additions & 9 deletions detector/yolov5_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ def __init__(self) -> None:
self.conf_threshold = float(os.getenv('CONF_THRESHOLD', '0.2'))

def init(self) -> None:
assert self.model_info is not None, 'model_info must be set before calling init()'
resolution = self.model_info.resolution
assert resolution is not None
engine_file = self._create_engine(resolution,
if self.model_info is None:
raise RuntimeError('Model info not initialized. Call load_model_info_and_init_model() first.')
if not isinstance(self.model_info.resolution, int) or self.model_info.resolution <= 0:
raise RuntimeError("resolution must be an integer > 0")

engine_file = self._create_engine(self.model_info.resolution,
len(self.model_info.categories),
self.model_info.model_size,
f'{self.model_info.model_root_path}/model.wts')
Expand Down Expand Up @@ -87,8 +89,10 @@ def clip_point(x: float, y: float, img_width: int, img_height: int) -> Tuple[flo
return x, y

def evaluate(self, image: bytes) -> ImageMetadata:
assert self.yolov5 is not None, 'init() must be executed first. Maybe loading the engine failed?!'
assert self.model_info is not None, 'model_info must be set before calling evaluate()'
if self.yolov5 is None:
raise RuntimeError('init() must be executed first. Maybe loading the engine failed?!')
if self.model_info is None:
raise RuntimeError('model_info must be set before calling evaluate()')

image_metadata = ImageMetadata()

Expand Down Expand Up @@ -130,9 +134,10 @@ def evaluate(self, image: bytes) -> ImageMetadata:
if skipped_detections:
log_msg = '\n'.join([str(d) for d in skipped_detections])
self.log.warning('Removed %d small detections from result: \n%s', len(skipped_detections), log_msg)
except Exception:
self.log.exception('inference failed')
return image_metadata
return image_metadata

except Exception as e:
raise RuntimeError('Error during inference') from e

def batch_evaluate(self, images: List[bytes]) -> ImagesMetadata:
raise NotImplementedError('batch_evaluate is not implemented for Yolov5Detector')
Expand Down
4 changes: 2 additions & 2 deletions detector_cpu/docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ fi

# ========================== BUILD CONFIGURATION / IMAGE SELECTION =======================

SEMANTIC_VERSION=0.1.11
NODE_LIB_VERSION=0.17.0
SEMANTIC_VERSION=0.1.12
NODE_LIB_VERSION=0.17.1
build_args=" --build-arg NODE_LIB_VERSION=$NODE_LIB_VERSION"


Expand Down
28 changes: 17 additions & 11 deletions detector_cpu/yolov5_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,20 @@ def __init__(self) -> None:
self.conf_threshold = float(os.getenv('CONF_THRESHOLD', '0.2'))

def init(self) -> None:
assert self.model_info is not None, 'model_info must be set before calling init()'
resolution = self.model_info.resolution
assert resolution is not None
pt_file = f'{self.model_info.model_root_path}/model.pt'
if self.model_info is None:
raise RuntimeError('Model info not initialized. Call load_model_info_and_init_model() first.')
if not isinstance(self.model_info.resolution, int) or self.model_info.resolution <= 0:
raise RuntimeError("model_info.resolution must be an integer > 0")

pt_file = f'{self.model_info.model_root_path}/model.pt'
yolov5_path = os.path.join(
os.path.dirname(__file__), 'app_code', 'yolov5')
self.yolov5 = torch.hub.load(
yolov5_path, 'custom', pt_file, source='local')
assert self.yolov5 is not None

if self.yolov5 is None:
raise RuntimeError('Failed to load YOLOv5 model')

self.yolov5.eval()

@staticmethod
Expand Down Expand Up @@ -76,11 +80,14 @@ def clip_point(x: float, y: float, img_width: int, img_height: int) -> Tuple[flo
return x, y

def evaluate(self, image: bytes) -> ImageMetadata:
assert self.yolov5 is not None, 'init() must be executed first!'
assert self.model_info is not None, 'model_info must be set before calling evaluate()'
if self.yolov5 is None:
raise RuntimeError('Model not initialized. Call load_model_info_and_init_model() first.')
if self.model_info is None:
raise RuntimeError('Model info not initialized. Call load_model_info_and_init_model() first.')

image_metadata = ImageMetadata()
assert self.model_info.resolution, "input_size must be an integer > 0"
if not isinstance(self.model_info.resolution, int) or self.model_info.resolution <= 0:
raise RuntimeError("input_size must be an integer > 0")
self.input_size = self.model_info.resolution

try:
Expand Down Expand Up @@ -144,9 +151,8 @@ def evaluate(self, image: bytes) -> ImageMetadata:
self.log.debug('took %f s', time.time() - t)
return image_metadata

except Exception:
self.log.exception('inference failed')
return image_metadata
except Exception as e:
raise RuntimeError('Error during inference') from e

def _preprocess_image(self, raw_bgr_image):
"""
Expand Down