dyhBUPT / StrongSORT

[TMM 2023] StrongSORT: Make DeepSORT Great Again
GNU General Public License v3.0
708 stars 75 forks source link

StrongSort metric -- NearestNeighborDistanceMetric switch to euclidean leads to error #84

Closed ChrCoello closed 1 year ago

ChrCoello commented 1 year ago

Hi I am learning the intricacies of the algorithm, and have been trying to play with the metric used to calculate the distance between current and past samples NearestNeighborDistanceMetric, l.37, strong_sort.py. If one shifts the initialisation from 'cosine' to 'euclidean' metric

metric = NearestNeighborDistanceMetric("euclidean", self.max_dist, nn_budget))

an error pops up at the third frame analyzed:

Frame timestamp: 2023-01-10T08:49:24.000000000
Frame timestamp: 2023-01-10T08:49:24.500000000
Frame timestamp: 2023-01-10T08:49:25.000000000
Traceback (most recent call last):
  File "C:\code\bin\python\python310\lib\runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\code\bin\python\python310\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "C:\code\tracking-inference\tracking\__main__.py", line 49, in <module>
    main(track_config)
  File "C:\code\tracking-inference\tracking\__main__.py", line 14, in main
    tracking(
  File "C:\code\tracking-inference\tracking\strongsort_norsvin.py", line 172, in tracking
    strongsort_run(
  File "C:\code\bin\pypoetry\cache\virtualenvs\tracking-lG4-SDJn-py3.10\lib\site-packages\torch\autograd\grad_mode.py", line 27, in decorate_context
    return func(*args, **kwargs)
  File "C:\code\tracking-inference\tracking\strongsort_norsvin.py", line 113, in strongsort_run
    outputs = tracker.update(response["det"].cpu(), ref_frame)
  File "C:\code\tracking-inference\tracking\trackers\strongsort\strong_sort.py", line 70, in update
    self.tracker.update(detections, clss, confs)
  File "C:\code\tracking-inference\tracking\trackers\strongsort\sort\tracker.py", line 93, in update
    self._match(detections)
  File "C:\code\tracking-inference\tracking\trackers\strongsort\sort\tracker.py", line 182, in _match
    linear_assignment.matching_cascade(
  File "C:\code\tracking-inference\tracking\trackers\strongsort\sort\linear_assignment.py", line 123, in matching_cascade
    min_cost_matching(
  File "C:\code\tracking-inference\tracking\trackers\strongsort\sort\linear_assignment.py", line 52, in min_cost_matching
    cost_matrix = distance_metric(
  File "C:\code\tracking-inference\tracking\trackers\strongsort\sort\tracker.py", line 169, in gated_metric
    cost_matrix = self.metric.distance(features, targets)
  File "C:\code\tracking-inference\tracking\trackers\strongsort\sort\nn_matching.py", line 161, in distance
    cost_matrix[i, :] = self._metric(self.samples[target], features)
  File "C:\code\tracking-inference\tracking\trackers\strongsort\sort\nn_matching.py", line 70, in _nn_euclidean_distance
    return np.maximum(0.0, torch.min(distances, axis=0)[0].numpy())
TypeError: min() received an invalid combination of arguments - got (numpy.ndarray, axis=int), but expected one of:
 * (Tensor input)
 * (Tensor input, Tensor other, *, Tensor out)
 * (Tensor input, int dim, bool keepdim, *, tuple of Tensors out)
 * (Tensor input, name dim, bool keepdim, *, tuple of Tensors out)

BR, Christopher

dyhBUPT commented 1 year ago

Hi, that's because you wrongly use the torch.min. Try to change axis=0 to dim=0.