11from collections import defaultdict
22from dataclasses import dataclass
3- from typing import Any , List , Optional , Tuple , Set
3+ from typing import Any , List , Optional , Set , Tuple
44
55import networkx as nx
66import numpy as np
@@ -39,7 +39,9 @@ def __init__(
3939 size_weight : float = 0.1 ,
4040 conf_weight : float = 0.1 ,
4141 ):
42- self .path_overlap_penalty = path_overlap_penalty if path_overlap_penalty is not None else 40
42+ self .path_overlap_penalty = (
43+ path_overlap_penalty if path_overlap_penalty is not None else 40
44+ )
4345 self .weight_key = "weight"
4446 self .source = "SOURCE"
4547 self .sink = "SINK"
@@ -58,7 +60,9 @@ def __init__(
5860 self .weights ["conf" ] = conf_weight
5961
6062 # Entry/exit region settings
61- self .entry_exit_regions : List [Tuple [int , int , int , int ]] = [] # (x1, y1, x2, y2)
63+ self .entry_exit_regions : List [
64+ Tuple [int , int , int , int ]
65+ ] = [] # (x1, y1, x2, y2)
6266
6367 # Border region settings
6468 self .use_border_regions = True
@@ -102,7 +106,9 @@ def set_border_entry_exit(
102106 frame_size (Tuple[int, int]): Size of the image (width, height).
103107 """
104108 self .use_border_regions = use_border
105- self .active_borders = borders if borders is not None else {"left" , "right" , "top" , "bottom" }
109+ self .active_borders = (
110+ borders if borders is not None else {"left" , "right" , "top" , "bottom" }
111+ )
106112 self .border_margin = margin
107113 self .frame_size = frame_size
108114
@@ -139,7 +145,9 @@ def _edge_cost(self, nodeU: TrackNode, nodeV: TrackNode) -> float:
139145
140146 area_a = (bboxU [2 ] - bboxU [0 ]) * (bboxU [3 ] - bboxU [1 ])
141147 area_b = (bboxV [2 ] - bboxV [0 ]) * (bboxV [3 ] - bboxV [1 ])
142- size_penalty = np .log ((max (area_a , area_b ) / (min (area_a , area_b ) + 1e-6 )) + 1e-6 )
148+ size_penalty = np .log (
149+ (max (area_a , area_b ) / (min (area_a , area_b ) + 1e-6 )) + 1e-6
150+ )
143151
144152 conf_penalty = 1 - min (conf_u , conf_v )
145153
@@ -208,7 +216,9 @@ def solve(self, k: Optional[int] = None) -> List[List[TrackNode]]:
208216 data [self .weight_key ] = base + penalty
209217
210218 try :
211- _ , path = nx .single_source_dijkstra (G_mod , self .source , self .sink , weight = self .weight_key )
219+ _ , path = nx .single_source_dijkstra (
220+ G_mod , self .source , self .sink , weight = self .weight_key
221+ )
212222 except nx .NetworkXNoPath :
213223 print (f"No path found from source to sink at { _i } th iteration" )
214224 break
0 commit comments