提交 e0847f18 编写于 作者: T tianyi1997 提交者: HydrogenSulfate

Update pretrained backbone

上级 f313a6d8
...@@ -175,6 +175,10 @@ def ResNet50_metabin(pretrained=False, ...@@ -175,6 +175,10 @@ def ResNet50_metabin(pretrained=False,
def bn2metabin(bn, pattern): def bn2metabin(bn, pattern):
metabin = MetaBIN(bn.weight.shape[0]) metabin = MetaBIN(bn.weight.shape[0])
metabin.batch_norm.weight.set_value(bn.weight)
metabin.batch_norm.bias.set_value(bn.bias)
metabin.batch_norm._variance.set_value(bn._variance)
metabin.batch_norm._mean.set_value(bn._mean)
return metabin return metabin
def setup_optimize_attr(model, bias_lr_factor): def setup_optimize_attr(model, bias_lr_factor):
...@@ -184,19 +188,16 @@ def ResNet50_metabin(pretrained=False, ...@@ -184,19 +188,16 @@ def ResNet50_metabin(pretrained=False,
if "bias" in name: if "bias" in name:
params.optimize_attr['learning_rate'] = bias_lr_factor params.optimize_attr['learning_rate'] = bias_lr_factor
stride_list = [2, 2, 2, 2, 1]
pattern = [] pattern = []
pattern.extend(["blocks[{}].conv{}.bn".format(i, j) \ pattern.extend(["blocks[{}].conv{}.bn".format(i, j) \
for i in range(16) for j in range(3)]) for i in range(16) for j in range(3)])
pattern.extend(["blocks[{}].short.bn".format(i) for i in [0, 3, 7, 13]]) pattern.extend(["blocks[{}].short.bn".format(i) for i in [0, 3, 7, 13]])
pattern.append("stem[0].bn") pattern.append("stem[0].bn")
model = ResNet50( model = ResNet50_last_stage_stride1(
pretrained=False, use_ssld=use_ssld, stride_list=stride_list, **kwargs) pretrained=pretrained, use_ssld=use_ssld, **kwargs)
model.upgrade_sublayer(pattern, bn2metabin) model.upgrade_sublayer(pattern, bn2metabin)
setup_optimize_attr(model=model, bias_lr_factor=bias_lr_factor) setup_optimize_attr(model=model, bias_lr_factor=bias_lr_factor)
_load_pretrained(pretrained, model, MODEL_URLS["ResNet50"], use_ssld)
return model return model
...@@ -29,7 +29,7 @@ Arch: ...@@ -29,7 +29,7 @@ Arch:
name: "RecModel" name: "RecModel"
Backbone: Backbone:
name: "ResNet50_metabin" name: "ResNet50_metabin"
pretrained: False pretrained: https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/others/resnet50-19c8e357_torch2paddle.pdparams
bias_lr_factor: 2.0 bias_lr_factor: 2.0
BackboneStopLayer: BackboneStopLayer:
name: "flatten" name: "flatten"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册