if 'conv3_final_bn' == name:
assert len(blobs) == 3, '{} layer blob count: {}'.format(name, len(blobs))
torch_mod['conv3_final_bn.running_mean'] = blobs[0].data
torch_mod['conv3_final_bn.running_var'] = blobs[1].data
elif 'conv3_final_scale' == name:
assert len(blobs) == 2, '{} layer blob count: {}'.format(name, len(blobs))
torch_mod['conv3_final_bn.weight'] = blobs[0].data
torch_mod['conv3_final_bn.bias'] = blobs[1].data
两个BatchNorm的行为不同。我还尝试设置conv3_final_bn.weight = 1和conv3_final_bn.bias = 0来验证caffe的BN层,结果也不匹配。
我应该如何处理错误的匹配?
答案 0 :(得分:0)
知道了! caffe的BatchNorm中仍有第三个参数。代码应为:
if 'conv3_final_bn' == name:
assert len(blobs) == 3, '{} layer blob count: {}'.format(name, len(blobs))
torch_mod['conv3_final_bn.running_mean'] = blobs[0].data / blobs[2].data[0]
torch_mod['conv3_final_bn.running_var'] = blobs[1].data / blobs[2].data[0]
elif 'conv3_final_scale' == name:
assert len(blobs) == 2, '{} layer blob count: {}'.format(name, len(blobs))
torch_mod['conv3_final_bn.weight'] = blobs[0].data
torch_mod['conv3_final_bn.bias'] = blobs[1].data