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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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 @@
"""
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')

Check warning on line 534 in mmengine/infer/infer.py

View check run for this annotation

Codecov / codecov/patch

mmengine/infer/infer.py#L534

Added line #L534 was not covered by tests
if isinstance(collate_fn_type, str):
collate_fn = registry.get(collate_fn_type)

Check warning on line 536 in mmengine/infer/infer.py

View check run for this annotation

Codecov / codecov/patch

mmengine/infer/infer.py#L536

Added line #L536 was not covered by tests
else:
collate_fn = collate_fn_type
from functools import partial
collate_fn = partial(collate_fn,

Check warning on line 540 in mmengine/infer/infer.py

View check run for this annotation

Codecov / codecov/patch

mmengine/infer/infer.py#L538-L540

Added lines #L538 - L540 were not covered by tests
**collate_fn_cfg) # type: ignore
elif callable(collate_fn_cfg):
collate_fn = collate_fn_cfg

Check warning on line 543 in mmengine/infer/infer.py

View check run for this annotation

Codecov / codecov/patch

mmengine/infer/infer.py#L543

Added line #L543 was not covered by tests
else:
raise TypeError(

Check warning on line 545 in mmengine/infer/infer.py

View check run for this annotation

Codecov / codecov/patch

mmengine/infer/infer.py#L545

Added line #L545 was not covered by tests
'collate_fn should be a dict or callable object, '
f'but got {collate_fn_cfg}')
Comment on lines +532 to +547
Copy link
Collaborator

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