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

[Enhance] Make the parameters of get_model_complexity_info() friendly #1056

Merged
merged 2 commits into from
Apr 10, 2023
Merged
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
7 changes: 6 additions & 1 deletion mmengine/analysis/print_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ def complexity_stats_table(

def get_model_complexity_info(
model: nn.Module,
input_shape: tuple,
input_shape: tuple = None,
inputs: Optional[torch.Tensor] = None,
show_table: bool = True,
show_arch: bool = True,
Expand All @@ -696,6 +696,11 @@ def get_model_complexity_info(
Returns:
dict: The complexity information of the model.
"""
if input_shape is None and inputs is None:
raise ValueError('One of "input_shape" and "inputs" should be set.')
elif input_shape is not None and inputs is not None:
raise ValueError('"input_shape" and "inputs" cannot be both set.')

if inputs is None:
inputs = (torch.randn(1, *input_shape), )

Expand Down