Simplify plus submit (#15941)

* remove unused annotate file

* improve plus error messages

* formatting
This commit is contained in:
Blake Blackshear 2025-01-11 08:04:11 -06:00 committed by GitHub
parent b8a74793ca
commit c4727f19e1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 33 additions and 41 deletions

View File

@ -151,7 +151,7 @@ class WebPushClient(Communicator): # type: ignore[misc]
camera: str = payload["after"]["camera"] camera: str = payload["after"]["camera"]
title = f"{', '.join(sorted_objects).replace('_', ' ').title()}{' was' if state == 'end' else ''} detected in {', '.join(payload['after']['data']['zones']).replace('_', ' ').title()}" title = f"{', '.join(sorted_objects).replace('_', ' ').title()}{' was' if state == 'end' else ''} detected in {', '.join(payload['after']['data']['zones']).replace('_', ' ').title()}"
message = f"Detected on {camera.replace('_', ' ').title()}" message = f"Detected on {camera.replace('_', ' ').title()}"
image = f'{payload["after"]["thumb_path"].replace("/media/frigate", "")}' image = f"{payload['after']['thumb_path'].replace('/media/frigate', '')}"
# if event is ongoing open to live view otherwise open to recordings view # if event is ongoing open to live view otherwise open to recordings view
direct_url = f"/review?id={reviewId}" if state == "end" else f"/#{camera}" direct_url = f"/review?id={reviewId}" if state == "end" else f"/#{camera}"

View File

@ -85,7 +85,7 @@ class ZoneConfig(BaseModel):
if explicit: if explicit:
self.coordinates = ",".join( self.coordinates = ",".join(
[ [
f'{round(int(p.split(",")[0]) / frame_shape[1], 3)},{round(int(p.split(",")[1]) / frame_shape[0], 3)}' f"{round(int(p.split(',')[0]) / frame_shape[1], 3)},{round(int(p.split(',')[1]) / frame_shape[0], 3)}"
for p in coordinates for p in coordinates
] ]
) )

View File

@ -219,19 +219,19 @@ class TensorRtDetector(DetectionApi):
] ]
def __init__(self, detector_config: TensorRTDetectorConfig): def __init__(self, detector_config: TensorRTDetectorConfig):
assert ( assert TRT_SUPPORT, (
TRT_SUPPORT f"TensorRT libraries not found, {DETECTOR_KEY} detector not present"
), f"TensorRT libraries not found, {DETECTOR_KEY} detector not present" )
(cuda_err,) = cuda.cuInit(0) (cuda_err,) = cuda.cuInit(0)
assert ( assert cuda_err == cuda.CUresult.CUDA_SUCCESS, (
cuda_err == cuda.CUresult.CUDA_SUCCESS f"Failed to initialize cuda {cuda_err}"
), f"Failed to initialize cuda {cuda_err}" )
err, dev_count = cuda.cuDeviceGetCount() err, dev_count = cuda.cuDeviceGetCount()
logger.debug(f"Num Available Devices: {dev_count}") logger.debug(f"Num Available Devices: {dev_count}")
assert ( assert detector_config.device < dev_count, (
detector_config.device < dev_count f"Invalid TensorRT Device Config. Device {detector_config.device} Invalid."
), f"Invalid TensorRT Device Config. Device {detector_config.device} Invalid." )
err, self.cu_ctx = cuda.cuCtxCreate( err, self.cu_ctx = cuda.cuCtxCreate(
cuda.CUctx_flags.CU_CTX_MAP_HOST, detector_config.device cuda.CUctx_flags.CU_CTX_MAP_HOST, detector_config.device
) )

View File

@ -68,11 +68,13 @@ class PlusApi:
or self._token_data["expires"] - datetime.datetime.now().timestamp() < 60 or self._token_data["expires"] - datetime.datetime.now().timestamp() < 60
): ):
if self.key is None: if self.key is None:
raise Exception("Plus API not activated") raise Exception(
"Plus API key not set. See https://docs.frigate.video/integrations/plus#set-your-api-key"
)
parts = self.key.split(":") parts = self.key.split(":")
r = requests.get(f"{self.host}/v1/auth/token", auth=(parts[0], parts[1])) r = requests.get(f"{self.host}/v1/auth/token", auth=(parts[0], parts[1]))
if not r.ok: if not r.ok:
raise Exception("Unable to refresh API token") raise Exception(f"Unable to refresh API token: {r.text}")
self._token_data = r.json() self._token_data = r.json()
def _get_authorization_header(self) -> dict: def _get_authorization_header(self) -> dict:
@ -116,15 +118,6 @@ class PlusApi:
logger.error(f"Failed to upload original: {r.status_code} {r.text}") logger.error(f"Failed to upload original: {r.status_code} {r.text}")
raise Exception(r.text) raise Exception(r.text)
# resize and submit annotate
files = {"file": get_jpg_bytes(image, 640, 70)}
data = presigned_urls["annotate"]["fields"]
data["content-type"] = "image/jpeg"
r = requests.post(presigned_urls["annotate"]["url"], files=files, data=data)
if not r.ok:
logger.error(f"Failed to upload annotate: {r.status_code} {r.text}")
raise Exception(r.text)
# resize and submit thumbnail # resize and submit thumbnail
files = {"file": get_jpg_bytes(image, 200, 70)} files = {"file": get_jpg_bytes(image, 200, 70)}
data = presigned_urls["thumbnail"]["fields"] data = presigned_urls["thumbnail"]["fields"]

View File

@ -983,10 +983,10 @@ class PtzAutoTracker:
logger.debug(f"{camera}: Zoom test: at max zoom: {at_max_zoom}") logger.debug(f"{camera}: Zoom test: at max zoom: {at_max_zoom}")
logger.debug(f"{camera}: Zoom test: at min zoom: {at_min_zoom}") logger.debug(f"{camera}: Zoom test: at min zoom: {at_min_zoom}")
logger.debug( logger.debug(
f'{camera}: Zoom test: zoom in hysteresis limit: {zoom_in_hysteresis} value: {AUTOTRACKING_ZOOM_IN_HYSTERESIS} original: {self.tracked_object_metrics[camera]["original_target_box"]} max: {self.tracked_object_metrics[camera]["max_target_box"]} target: {calculated_target_box if calculated_target_box else self.tracked_object_metrics[camera]["target_box"]}' f"{camera}: Zoom test: zoom in hysteresis limit: {zoom_in_hysteresis} value: {AUTOTRACKING_ZOOM_IN_HYSTERESIS} original: {self.tracked_object_metrics[camera]['original_target_box']} max: {self.tracked_object_metrics[camera]['max_target_box']} target: {calculated_target_box if calculated_target_box else self.tracked_object_metrics[camera]['target_box']}"
) )
logger.debug( logger.debug(
f'{camera}: Zoom test: zoom out hysteresis limit: {zoom_out_hysteresis} value: {AUTOTRACKING_ZOOM_OUT_HYSTERESIS} original: {self.tracked_object_metrics[camera]["original_target_box"]} max: {self.tracked_object_metrics[camera]["max_target_box"]} target: {calculated_target_box if calculated_target_box else self.tracked_object_metrics[camera]["target_box"]}' f"{camera}: Zoom test: zoom out hysteresis limit: {zoom_out_hysteresis} value: {AUTOTRACKING_ZOOM_OUT_HYSTERESIS} original: {self.tracked_object_metrics[camera]['original_target_box']} max: {self.tracked_object_metrics[camera]['max_target_box']} target: {calculated_target_box if calculated_target_box else self.tracked_object_metrics[camera]['target_box']}"
) )
# Zoom in conditions (and) # Zoom in conditions (and)
@ -1069,7 +1069,7 @@ class PtzAutoTracker:
pan = ((centroid_x / camera_width) - 0.5) * 2 pan = ((centroid_x / camera_width) - 0.5) * 2
tilt = (0.5 - (centroid_y / camera_height)) * 2 tilt = (0.5 - (centroid_y / camera_height)) * 2
logger.debug(f'{camera}: Original box: {obj.obj_data["box"]}') logger.debug(f"{camera}: Original box: {obj.obj_data['box']}")
logger.debug(f"{camera}: Predicted box: {tuple(predicted_box)}") logger.debug(f"{camera}: Predicted box: {tuple(predicted_box)}")
logger.debug( logger.debug(
f"{camera}: Velocity: {tuple(np.round(average_velocity).flatten().astype(int))}" f"{camera}: Velocity: {tuple(np.round(average_velocity).flatten().astype(int))}"
@ -1179,7 +1179,7 @@ class PtzAutoTracker:
) )
zoom = (ratio - 1) / (ratio + 1) zoom = (ratio - 1) / (ratio + 1)
logger.debug( logger.debug(
f'{camera}: limit: {self.tracked_object_metrics[camera]["max_target_box"]}, ratio: {ratio} zoom calculation: {zoom}' f"{camera}: limit: {self.tracked_object_metrics[camera]['max_target_box']}, ratio: {ratio} zoom calculation: {zoom}"
) )
if not result: if not result:
# zoom out with special condition if zooming out because of velocity, edges, etc. # zoom out with special condition if zooming out because of velocity, edges, etc.

View File

@ -256,7 +256,7 @@ class ReviewSegmentMaintainer(threading.Thread):
elif object["sub_label"][0] in self.config.model.all_attributes: elif object["sub_label"][0] in self.config.model.all_attributes:
segment.detections[object["id"]] = object["sub_label"][0] segment.detections[object["id"]] = object["sub_label"][0]
else: else:
segment.detections[object["id"]] = f'{object["label"]}-verified' segment.detections[object["id"]] = f"{object['label']}-verified"
segment.sub_labels[object["id"]] = object["sub_label"][0] segment.sub_labels[object["id"]] = object["sub_label"][0]
# if object is alert label # if object is alert label
@ -352,7 +352,7 @@ class ReviewSegmentMaintainer(threading.Thread):
elif object["sub_label"][0] in self.config.model.all_attributes: elif object["sub_label"][0] in self.config.model.all_attributes:
detections[object["id"]] = object["sub_label"][0] detections[object["id"]] = object["sub_label"][0]
else: else:
detections[object["id"]] = f'{object["label"]}-verified' detections[object["id"]] = f"{object['label']}-verified"
sub_labels[object["id"]] = object["sub_label"][0] sub_labels[object["id"]] = object["sub_label"][0]
# if object is alert label # if object is alert label

View File

@ -72,8 +72,7 @@ class BaseServiceProcess(Service, ABC):
running = False running = False
except TimeoutError: except TimeoutError:
self.manager.logger.warning( self.manager.logger.warning(
f"{self.name} is still running after " f"{self.name} is still running after {timeout} seconds. Killing."
f"{timeout} seconds. Killing."
) )
if running: if running: