Skip to content

Use enumerate to get index of ModuleList #4534

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

Merged
merged 5 commits into from
Oct 5, 2021
Merged
Show file tree
Hide file tree
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
4 changes: 1 addition & 3 deletions torchvision/models/detection/ssd.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,10 @@ def _get_result_from_module_list(self, x: Tensor, idx: int) -> Tensor:
num_blocks = len(self.module_list)
if idx < 0:
idx += num_blocks
i = 0
out = x
for module in self.module_list:
for i, module in enumerate(self.module_list):
if i == idx:
out = module(x)
i += 1
return out

def forward(self, x: List[Tensor]) -> Tensor:
Expand Down
8 changes: 2 additions & 6 deletions torchvision/ops/feature_pyramid_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,10 @@ def get_result_from_inner_blocks(self, x: Tensor, idx: int) -> Tensor:
num_blocks = len(self.inner_blocks)
if idx < 0:
idx += num_blocks
i = 0
out = x
for module in self.inner_blocks:
for i, module in enumerate(self.inner_blocks):
if i == idx:
out = module(x)
i += 1
return out

def get_result_from_layer_blocks(self, x: Tensor, idx: int) -> Tensor:
Expand All @@ -119,12 +117,10 @@ def get_result_from_layer_blocks(self, x: Tensor, idx: int) -> Tensor:
num_blocks = len(self.layer_blocks)
if idx < 0:
idx += num_blocks
i = 0
out = x
for module in self.layer_blocks:
for i, module in enumerate(self.layer_blocks):
if i == idx:
out = module(x)
i += 1
return out

def forward(self, x: Dict[str, Tensor]) -> Dict[str, Tensor]:
Expand Down