import torch
import copy
def change_pth(input_pth, out_pth):
model_dir = input_pth
checkpoint = torch.load(model_dir)
model = copy.deepcopy(checkpoint)
for name, param in model['state_dict'].items():
if name == 'bbox_head.multi_level_conv_cls.0.weight' or name == 'bbox_head.multi_level_conv_cls.1.weight' or name == 'bbox_head.multi_level_conv_cls.2.weight':
temp_param = param.data
print("weight temp_param shape :", temp_param.shape)
new_param = temp_param[:1,]
print("weight new shape :", temp_param.shape)
param.data = new_param
model['state_dict'][name] = param
if name == 'bbox_head.multi_level_conv_cls.0.bias' or name == 'bbox_head.multi_level_conv_cls.1.bias' or name == 'bbox_head.multi_level_conv_cls.2.bias':
temp_param = param.data
print("bias temp_param shape :", temp_param.shape)
new_param = temp_param[:1,]
print("bias new shape :", temp_param.shape)
param.data = new_param
model['state_dict'][name] = param
print('{}, size:{}'.format(name, param.data.size()))
torch.save(model, out_pth)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)