Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnboundLocalError when calculating HOTA #193

Open
mikel-brostrom opened this issue Jul 4, 2024 · 1 comment
Open

UnboundLocalError when calculating HOTA #193

mikel-brostrom opened this issue Jul 4, 2024 · 1 comment

Comments

@mikel-brostrom
Copy link

mikel-brostrom commented Jul 4, 2024

I am running this:

import os
import numpy as np
import motmetrics as mm

def compute_motchallenge(gt_file, test_file):

    df_gt = mm.io.loadtxt(gt_file)
    df_test = mm.io.loadtxt(test_file)

    # Define thresholds for matching
    th_list = np.arange(0.05, 0.99, 0.05)
    # Compare ground truth and test data
    res_list = mm.utils.compare_to_groundtruth_reweighting(df_gt, df_test, "iou", distth=th_list)
    return res_list

def process_multiple_files(gt_files, test_files):
    accumulators = []
    for gt_file, test_file in zip(gt_files, test_files):
        acc = compute_motchallenge(gt_file, test_file)
        accumulators.append(acc)
    
    return accumulators

gt_files = ['./gt.txt']
test_files = ['./test.txt']

accumulators = process_multiple_files(gt_files, test_files)
mh = mm.metrics.create()

summary = mh.compute_many(
    acc,
    metrics=[
        "deta_alpha",
        "assa_alpha",
        "hota_alpha",
    ],
    generate_overall=True,  # `Overall` is the average we need only
)
strsummary = mm.io.render_summary(
    summary.iloc[[-1], :],  # Use list to preserve `DataFrame` type
    formatters=mh.formatters,
    namemap={"hota_alpha": "HOTA", "assa_alpha": "ASSA", "deta_alpha": "DETA"},
)
print(strsummary)

but I get the following error:

  File "/Users/mikel.brostrom/boxmot/try_pymotmetrics.py", line 14, in compute_motchallenge
    res_list = mm.utils.compare_to_groundtruth_reweighting(df_gt, df_test, "iou", distth=th_list)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mikel.brostrom/Library/Caches/pypoetry/virtualenvs/boxmot-YDNZdsaB-py3.11/lib/python3.11/site-packages/motmetrics/utils.py", line 156, in compare_to_groundtruth_reweighting
    acc.update(oids, hids, 1 - weighted_dists, frameid=fid, similartiy_matrix=dists, th=th)
                                                                              ^^^^^
UnboundLocalError: cannot access local variable 'dists' where it is not associated with a value

The files used:

gt.txt
test.txt

Any idea what the error may be here @Justin900429. Just following the README 😄

@mikel-brostrom
Copy link
Author

mikel-brostrom commented Jul 4, 2024

Fix proposal:

develop...mikel-brostrom:py-motmetrics:patch-1

After this, HOTA runs without problems:

(boxmot-py3.11) ➜  boxmot git:(pymotmetrics) ✗ python3 try_pymotmetrics.py
        DETA  ASSA  HOTA
OVERALL 7.7% 70.0% 23.2%
@mikel-brostrom mikel-brostrom changed the title Error when calculating HOTA Jul 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant