mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-05 02:35:22 +03:00
Refactor DeepStack label loading from file to use merged labelmap
This commit is contained in:
parent
2794cd0593
commit
1a2f8c568e
@ -28,32 +28,11 @@ class DeepStack(DetectionApi):
|
|||||||
self.api_url = detector_config.api_url
|
self.api_url = detector_config.api_url
|
||||||
self.api_timeout = detector_config.api_timeout
|
self.api_timeout = detector_config.api_timeout
|
||||||
self.api_key = detector_config.api_key
|
self.api_key = detector_config.api_key
|
||||||
self.labels = self.load_labels("/labelmap.txt")
|
self.labels = detector_config.model.merged_labelmap
|
||||||
|
|
||||||
self.h = detector_config.model.height
|
self.h = detector_config.model.height
|
||||||
self.w = detector_config.model.width
|
self.w = detector_config.model.width
|
||||||
|
|
||||||
def load_labels(self, path, encoding="utf-8"):
|
|
||||||
"""Loads labels from file (with or without index numbers).
|
|
||||||
Args:
|
|
||||||
path: path to label file.
|
|
||||||
encoding: label file encoding.
|
|
||||||
Returns:
|
|
||||||
Dictionary mapping indices to labels.
|
|
||||||
"""
|
|
||||||
with open(path, "r", encoding=encoding) as f:
|
|
||||||
labels = {index: "unknown" for index in range(91)}
|
|
||||||
lines = f.readlines()
|
|
||||||
if not lines:
|
|
||||||
return {}
|
|
||||||
|
|
||||||
if lines[0].split(" ", maxsplit=1)[0].isdigit():
|
|
||||||
pairs = [line.split(" ", maxsplit=1) for line in lines]
|
|
||||||
labels.update({int(index): label.strip() for index, label in pairs})
|
|
||||||
else:
|
|
||||||
labels.update({index: line.strip() for index, line in enumerate(lines)})
|
|
||||||
return labels
|
|
||||||
|
|
||||||
def get_label_index(self, label_value):
|
def get_label_index(self, label_value):
|
||||||
if label_value.lower() == 'truck':
|
if label_value.lower() == 'truck':
|
||||||
label_value = 'car'
|
label_value = 'car'
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user