Skip to content

Commit ff16a77

Browse files
prabhat00155facebook-github-bot
authored andcommitted
[fbsync] Use enumerate to get index of ModuleList (#4534)
Summary: Co-authored-by: Nicolas Hug <[email protected]> Reviewed By: NicolasHug Differential Revision: D31505569 fbshipit-source-id: 78967c474a3818a8dc5fe259e9b9e7773d91d45e
1 parent 9634b23 commit ff16a77

File tree

2 files changed

+3
-9
lines changed

2 files changed

+3
-9
lines changed

torchvision/models/detection/ssd.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,10 @@ def _get_result_from_module_list(self, x: Tensor, idx: int) -> Tensor:
6262
num_blocks = len(self.module_list)
6363
if idx < 0:
6464
idx += num_blocks
65-
i = 0
6665
out = x
67-
for module in self.module_list:
66+
for i, module in enumerate(self.module_list):
6867
if i == idx:
6968
out = module(x)
70-
i += 1
7169
return out
7270

7371
def forward(self, x: List[Tensor]) -> Tensor:

torchvision/ops/feature_pyramid_network.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,10 @@ def get_result_from_inner_blocks(self, x: Tensor, idx: int) -> Tensor:
103103
num_blocks = len(self.inner_blocks)
104104
if idx < 0:
105105
idx += num_blocks
106-
i = 0
107106
out = x
108-
for module in self.inner_blocks:
107+
for i, module in enumerate(self.inner_blocks):
109108
if i == idx:
110109
out = module(x)
111-
i += 1
112110
return out
113111

114112
def get_result_from_layer_blocks(self, x: Tensor, idx: int) -> Tensor:
@@ -119,12 +117,10 @@ def get_result_from_layer_blocks(self, x: Tensor, idx: int) -> Tensor:
119117
num_blocks = len(self.layer_blocks)
120118
if idx < 0:
121119
idx += num_blocks
122-
i = 0
123120
out = x
124-
for module in self.layer_blocks:
121+
for i, module in enumerate(self.layer_blocks):
125122
if i == idx:
126123
out = module(x)
127-
i += 1
128124
return out
129125

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

0 commit comments

Comments
 (0)