Skip to content

Commit 95c8057

Browse files
authored
Static method; minor opts
1 parent 85b2cd6 commit 95c8057

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/modules/ObjectDetectionCoral/tpu_runner.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -474,8 +474,8 @@ def _watchdog(self):
474474

475475
logging.debug("Watchdog caught shutdown in {}".format(threading.get_ident()))
476476

477-
478-
def _get_tpu_devices(self):
477+
@staticmethod
478+
def get_tpu_devices(tpu_limit: int = -1):
479479
"""Returns list of device names in usb:N or pci:N format.
480480
481481
This function prefers returning PCI Edge TPU first.
@@ -494,8 +494,8 @@ def _get_tpu_devices(self):
494494
tpu_l = ['pci:%d' % i for i in range(min(len(edge_tpus), num_pci_devices))] + \
495495
['usb:%d' % i for i in range(max(0, len(edge_tpus) - num_pci_devices))]
496496

497-
if self.tpu_limit > 0:
498-
return tpu_l[:self.tpu_limit]
497+
if tpu_limit > 0:
498+
return tpu_l[:tpu_limit]
499499
else:
500500
return tpu_l
501501

@@ -560,7 +560,7 @@ def init_pipe(self, options: Options) -> tuple:
560560

561561
error = ""
562562

563-
tpu_list = self._get_tpu_devices()
563+
tpu_list = TPURunner.get_tpu_devices(self.tpu_limit)
564564
self.model_name = options.model_name
565565
self.model_size = options.model_size
566566

@@ -867,10 +867,10 @@ def _decode_result(self, result_list, score_threshold: float):
867867
def _xywh2xyxy(self, xywh):
868868
# Convert nx4 boxes from [x, y, w, h] to [x1, y1, x2, y2] where xy1=top-left, xy2=bottom-right
869869
xyxy = np.copy(xywh)
870-
xyxy[:, 1] = xywh[:, 0] - xywh[:, 2] / 2 # top left x
871-
xyxy[:, 0] = xywh[:, 1] - xywh[:, 3] / 2 # top left y
872-
xyxy[:, 3] = xywh[:, 0] + xywh[:, 2] / 2 # bottom right x
873-
xyxy[:, 2] = xywh[:, 1] + xywh[:, 3] / 2 # bottom right y
870+
xyxy[:, 1] = xywh[:, 0] - xywh[:, 2] * 0.5 # top left x
871+
xyxy[:, 0] = xywh[:, 1] - xywh[:, 3] * 0.5 # top left y
872+
xyxy[:, 3] = xywh[:, 0] + xywh[:, 2] * 0.5 # bottom right x
873+
xyxy[:, 2] = xywh[:, 1] + xywh[:, 3] * 0.5 # bottom right y
874874
return xyxy
875875

876876

0 commit comments

Comments
 (0)