写了个垃圾代码,我受不了了,这段代码可以实现更改字典的键,其他的用处没有很大,奶奶滴,浪费我时间
for key in list(pre_trained_dict['model_spe'].keys()): # [2:77]
if key == 'norm.weight' or key == 'norm.bias':
continue
else:
for k in list(new_model_dict.keys()):
if k == 'norm.weight' or k == 'norm.bias':
continue
else:
a, b = k.split('_', 1)
if b == key:
new_key = "spe_" + key
pre_trained_dict['model_spe'].update({new_key: pre_trained_dict['model_spe'].pop(key)})
for key in list(pre_trained_dict['model_spa'].keys()): # [2:50]
if key == 'norm.weight' or key == 'norm.bias':
continue
else:
for k in list(new_model_dict.keys()):
if k == 'norm.weight' or k == 'norm.bias':
continue
else:
a, b = k.split('_', 1)
if b == key:
new_key = "spa_" + key
pre_trained_dict['model_spa'].update({new_key: pre_trained_dict['model_spa'].pop(key)})
放这保存一下吧。