mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-05 18:55:23 +03:00
Refactor DeepStack plugin with client initialization and closing
This commit is contained in:
parent
c7d2fbeeb1
commit
35d23a0044
@ -32,6 +32,7 @@ class DeepStack(DetectionApi):
|
||||
self.api_timeout = detector_config.api_timeout
|
||||
self.api_key = detector_config.api_key
|
||||
self.labels = detector_config.model.merged_labelmap
|
||||
self.client = httpx.Client()
|
||||
|
||||
def get_label_index(self, label_value):
|
||||
if label_value.lower() == "truck":
|
||||
@ -50,14 +51,14 @@ class DeepStack(DetectionApi):
|
||||
image_bytes = output.getvalue()
|
||||
data = {"api_key": self.api_key}
|
||||
try:
|
||||
response = httpx.post(
|
||||
response = self.client.post(
|
||||
self.api_url,
|
||||
data=data,
|
||||
files={"image": image_bytes},
|
||||
timeout=self.api_timeout,
|
||||
)
|
||||
response_json = response.json()
|
||||
except httpx.RequestError as e:
|
||||
except (httpx.RequestError, httpx.TimeoutException) as e:
|
||||
logger.error(f"An error occurred while making the request: {e}")
|
||||
return np.zeros((20, 6), np.float32)
|
||||
|
||||
@ -85,3 +86,6 @@ class DeepStack(DetectionApi):
|
||||
]
|
||||
|
||||
return detections
|
||||
|
||||
def close(self):
|
||||
self.client.close()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user