in mobile_cv/arch/fbnet_v2/fbnet_builder.py [0:0]
def expand_repeats(blocks_info):
"""Expand repeats in block cfg to multiple blocks and remove `_repeat_`
Special handling for stride when repeat > 1 that the additionally expanded
blocks will have stride 1
"""
_check_is_list(blocks_info)
ret = []
for stage_cfgs in blocks_info:
_check_is_list(stage_cfgs)
cur_stage = []
for block_cfg in stage_cfgs:
assert isinstance(block_cfg, dict) and "block_cfg" in block_cfg
cur_cfg = copy.deepcopy(block_cfg)
repeat = cur_cfg.pop("repeat", 1)
assert repeat >= 0
# skip the block if repeat == 0
if repeat == 0:
continue
expanded_cfgs = [copy.deepcopy(cur_cfg) for _ in range(repeat)]
stride = cur_cfg["block_cfg"].get("stride", None)
if repeat > 1 and stride is not None:
# setup all strides to 1 except the first block
for cur in expanded_cfgs[1:]:
cur["block_cfg"]["stride"] = 1
cur_stage += expanded_cfgs
ret.append(cur_stage)
return ret