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

[Fix] fix infer.py _init_collate incompatibility problem #1360

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 16 additions & 1 deletion mmengine/infer/infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,22 @@ def preprocess(self, inputs, batch_size, **kwargs):
"""
try:
with FUNCTIONS.switch_scope_and_registry(self.scope) as registry:
collate_fn = registry.get(cfg.test_dataloader.collate_fn)
collate_fn_cfg = cfg.test_dataloader.collate_fn
if isinstance(collate_fn_cfg, dict):
collate_fn_type = collate_fn_cfg.pop('type')
if isinstance(collate_fn_type, str):
collate_fn = registry.get(collate_fn_type)
else:
collate_fn = collate_fn_type
from functools import partial
collate_fn = partial(collate_fn,
**collate_fn_cfg) # type: ignore
elif callable(collate_fn_cfg):
collate_fn = collate_fn_cfg
else:
raise TypeError(
'collate_fn should be a dict or callable object, '
f'but got {collate_fn_cfg}')
Comment on lines +532 to +547
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can move the changes here to build_collate_fn, and at the same time, the logic in build_dataloader can replace with this function.

except AttributeError:
collate_fn = pseudo_collate
return collate_fn # type: ignore
Expand Down