Skip to content

Commit

Permalink
safe refactoring (blakeblackshear#2552)
Browse files Browse the repository at this point in the history
Co-authored-by: YS <ys@gm.com>
  • Loading branch information
2 people authored and NickM-27 committed Feb 20, 2022
1 parent 2994811 commit 58aeb25
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions frigate/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,24 @@ def add_mask(mask, mask_img):
)
cv2.fillPoly(mask_img, pts=[contour], color=(0))

def load_labels(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:
lines = f.readlines()
if not lines:
return {}

if lines[0].split(" ", maxsplit=1)[0].isdigit():
pairs = [line.split(" ", maxsplit=1) for line in lines]
return {int(index): label.strip() for index, label in pairs}
else:
return {index: line.strip() for index, line in enumerate(lines)}

def load_labels(path, encoding="utf-8"):
"""Loads labels from file (with or without index numbers).
Expand Down

0 comments on commit 58aeb25

Please sign in to comment.