open-mmlab / mmtracking

OpenMMLab Video Perception Toolbox. It supports Video Object Detection (VID), Multiple Object Tracking (MOT), Single Object Tracking (SOT), Video Instance Segmentation (VIS) with a unified framework.
https://mmtracking.readthedocs.io/en/latest/
Apache License 2.0
3.5k stars 586 forks source link

Deep copy for the hyper-parameter search config #441

Open wgting96 opened 2 years ago

wgting96 commented 2 years ago

Issue

https://github.com/open-mmlab/mmtracking/blob/3c45b9019c83801c65c40959e65f2ed5c7b97e53/tools/analysis/mot/mot_param_search.py#L144-L149

The dict.copy() method is not applied to its children recursively. The values from the sub-dict are not correctly copied.

A minimal code snippet to reproduce


from dotty_dict import dotty

tracker = dict(
    type='ByteTracker',
    obj_score_thrs=dict(high=[0.5, 0.6], low=0.1),
)

search_cfgs= []
for c in [0.5, 0.6]:
    search_cfg = dotty(tracker.copy())
    search_cfg['obj_score_thrs.high'] = c
    searech_cfgs.append(dict(search_cfg))

print(search_cfgs[0])
print(search_cfgs[1])

Output:

{'type': 'ByteTracker', 'obj_score_thrs': {'high': 0.6, 'low': 0.1}}
{'type': 'ByteTracker', 'obj_score_thrs': {'high': 0.6, 'low': 0.1}}

Quick fix:

use deepcopy method to construct a new dict object.

import copy
from dotty_dict import dotty

tracker = dict(
    type='ByteTracker',
    obj_score_thrs=dict(high=[0.5, 0.6], low=0.1),
)

search_cfgs= []
for c in [0.5, 0.6]:
    search_cfg = dotty(copy.deepcopy(tracker))
    search_cfg['obj_score_thrs.high'] = c
    search_cfgs.append(dict(search_cfg))

print(search_cfgs[0])
print(search_cfgs[1])

Output:

{'type': 'ByteTracker', 'obj_score_thrs': {'high': 0.5, 'low': 0.1}}
{'type': 'ByteTracker', 'obj_score_thrs': {'high': 0.6, 'low': 0.1}}
Seerkfang commented 2 years ago

Thanks for your correction. Would you like to open a pull request to fix this?