以mmaction中的tsn+resnet50+kinetics
训练的模型作为预训练模型,拿来训练TSN+resnet+ucf101
。
建立文件tools/transfer_model.py
。
在mmaction/modelzoo中找到TSN的kinectis模型,并下载。
因为kinetics数据集共有400类,所以最后一层分类层的权重W
为(400,2048)
,bias
为(400)。
ucf101数据集共有101类。
不同的预训练文件可能结构不太一样?以TSN的kinectis模型作为例子,用torch.load(model_dir)
加载后得到一个dict
文件checkpoint
,这个文件里面还有两个键,分别为meta
和state_dict
,meta
存的是模型相关配置数据,state_dict
存的是模型训练后得到的每一层的权重值。
state_dict
中以name
为key,param
为value,param
也是一个dict
,param
中有data
这个key
,里面存储的都是torch类型的数据。
所以修改思路就是把模型最后一层分类层的W
数据改为(101,2048)
,bias
改为(101)
。下面的代码是数值统一改为1。
最后将模型保存为.pth
格式,直接可以用了。
关于mmaction中的--resume_from
,适用于训练过程中被突然打断,--load_from
,适用于迁移模型,所以这个修改后的模型用的是--load_from
。
from __future__ import print_function
from __future__ import division
import torch
import copy
# model_dir = '/media/data2/ggwang/modelzoo/tsn/tsn2d_kinetics400_rgb_r50_seg3_f1s1-b702e12f.pth'
model_dir = '/path/to/your/pretrained/model'
checkpoint = torch.load(model_dir) # 加载模型,checkpoint是一个dict
model = copy.deepcopy(checkpoint) # 复制checkpoint,并修改
for name, param in model['state_dict'].items():
if name=='cls_head.fc_cls.weight':
param.data = torch.ones(101, 2048)
model['state_dict'][name] = param
if name=='cls_head.fc_cls.bias':
param.data = torch.ones(101)
model['state_dict'][name] = param
print('{},size:{}'.format(name, param.data.size()))
torch.save(model, '/media/data2/ggwang/modelzoo/tsn/resnet_kinetics_ucf101.pth')
print出的为:也就是每一层的名字和参数的shape。
backbone.conv1.weight,size:torch.Size([64, 3, 7, 7])
backbone.bn1.weight,size:torch.Size([64])
backbone.bn1.bias,size:torch.Size([64])
backbone.bn1.running_mean,size:torch.Size([64])
backbone.bn1.running_var,size:torch.Size([64])
backbone.bn1.num_batches_tracked,size:torch.Size([])
backbone.layer1.0.conv1.weight,size:torch.Size([64, 64, 1, 1])
backbone.layer1.0.conv2.weight,size:torch.Size([64, 64, 3, 3])
backbone.layer1.0.bn1.weight,size:torch.Size([64])
backbone.layer1.0.bn1.bias,size:torch.Size([64])
backbone.layer1.0.bn1.running_mean,size:torch.Size([64])
backbone.layer1.0.bn1.running_var,size:torch.Size([64])
backbone.layer1.0.bn1.num_batches_tracked,size:torch.Size([])
backbone.layer1.0.bn2.weight,size:torch.Size([64])
backbone.layer1.0.bn2.bias,size:torch.Size([64])
backbone.layer1.0.bn2.running_mean,size:torch.Size([64])
backbone.layer1.0.bn2.running_var,size:torch.Size([64])
backbone.layer1.0.bn2.num_batches_tracked,size:torch.Size([])
backbone.layer1.0.conv3.weight,size:torch.Size([256, 64, 1, 1])
backbone.layer1.0.bn3.weight,size:torch.Size([256])
backbone.layer1.0.bn3.bias,size:torch.Size([256])
backbone.layer1.0.bn3.running_mean,size:torch.Size([256])
backbone.layer1.0.bn3.running_var,size:torch.Size([256])
backbone.layer1.0.bn3.num_batches_tracked,size:torch.Size([])
backbone.layer1.0.downsample.0.weight,size:torch.Size([256, 64, 1, 1])
backbone.layer1.0.downsample.1.weight,size:torch.Size([256])
backbone.layer1.0.downsample.1.bias,size:torch.Size([256])
backbone.layer1.0.downsample.1.running_mean,size:torch.Size([256])
backbone.layer1.0.downsample.1.running_var,size:torch.Size([256])
backbone.layer1.0.downsample.1.num_batches_tracked,size:torch.Size([])
backbone.layer1.1.conv1.weight,size:torch.Size([64, 256, 1, 1])
backbone.layer1.1.conv2.weight,size:torch.Size([64, 64, 3, 3])
backbone.layer1.1.bn1.weight,size:torch.Size([64])
backbone.layer1.1.bn1.bias,size:torch.Size([64])
backbone.layer1.1.bn1.running_mean,size:torch.Size([64])
backbone.layer1.1.bn1.running_var,size:torch.Size([64])
backbone.layer1.1.bn1.num_batches_tracked,size:torch.Size([])
backbone.layer1.1.bn2.weight,size:torch.Size([64])
backbone.layer1.1.bn2.bias,size:torch.Size([64])
backbone.layer1.1.bn2.running_mean,size:torch.Size([64])
backbone.layer1.1.bn2.running_var,size:torch.Size([64])
backbone.layer1.1.bn2.num_batches_tracked,size:torch.Size([])
backbone.layer1.1.conv3.weight,size:torch.Size([256, 64, 1, 1])
backbone.layer1.1.bn3.weight,size:torch.Size([256])
backbone.layer1.1.bn3.bias,size:torch.Size([256])
backbone.layer1.1.bn3.running_mean,size:torch.Size([256])
backbone.layer1.1.bn3.running_var,size:torch.Size([256])
backbone.layer1.1.bn3.num_batches_tracked,size:torch.Size([])
backbone.layer1.2.conv1.weight,size:torch.Size([64, 256, 1, 1])
backbone.layer1.2.conv2.weight,size:torch.Size([64, 64, 3, 3])
backbone.layer1.2.bn1.weight,size:torch.Size([64])
backbone.layer1.2.bn1.bias,size:torch.Size([64])
backbone.layer1.2.bn1.running_mean,size:torch.Size([64])
backbone.layer1.2.bn1.running_var,size:torch.Size([64])
backbone.layer1.2.bn1.num_batches_tracked,size:torch.Size([])
backbone.layer1.2.bn2.weight,size:torch.Size([64])
backbone.layer1.2.bn2.bias,size:torch.Size([64])
backbone.layer1.2.bn2.running_mean,size:torch.Size([64])
backbone.layer1.2.bn2.running_var,size:torch.Size([64])
backbone.layer1.2.bn2.num_batches_tracked,size:torch.Size([])
backbone.layer1.2.conv3.weight,size:torch.Size([256, 64, 1, 1])
backbone.layer1.2.bn3.weight,size:torch.Size([256])
backbone.layer1.2.bn3.bias,size:torch.Size([256])
backbone.layer1.2.bn3.running_mean,size:torch.Size([256])
backbone.layer1.2.bn3.running_var,size:torch.Size([256])
backbone.layer1.2.bn3.num_batches_tracked,size:torch.Size([])
backbone.layer2.0.conv1.weight,size:torch.Size([128, 256, 1, 1])
backbone.layer2.0.conv2.weight,size:torch.Size([128, 128, 3, 3])
backbone.layer2.0.bn1.weight,size:torch.Size([128])
backbone.layer2.0.bn1.bias,size:torch.Size([128])
backbone.layer2.0.bn1.running_mean,size:torch.Size([128])
backbone.layer2.0.bn1.running_var,size:torch.Size([128])
backbone.layer2.0.bn1.num_batches_tracked,size:torch.Size([])
backbone.layer2.0.bn2.weight,size:torch.Size([128])
backbone.layer2.0.bn2.bias,size:torch.Size([128])
backbone.layer2.0.bn2.running_mean,size:torch.Size([128])
backbone.layer2.0.bn2.running_var,size:torch.Size([128])
backbone.layer2.0.bn2.num_batches_tracked,size:torch.Size([])
backbone.layer2.0.conv3.weight,size:torch.Size([512, 128, 1, 1])
backbone.layer2.0.bn3.weight,size:torch.Size([512])
backbone.layer2.0.bn3.bias,size:torch.Size([512])
backbone.layer2.0.bn3.running_mean,size:torch.Size([512])
backbone.layer2.0.bn3.running_var,size:torch.Size([512])
backbone.layer2.0.bn3.num_batches_tracked,size:torch.Size([])
backbone.layer2.0.downsample.0.weight,size:torch.Size([512, 256, 1, 1])
backbone.layer2.0.downsample.1.weight,size:torch.Size([512])
backbone.layer2.0.downsample.1.bias,size:torch.Size([512])
backbone.layer2.0.downsample.1.running_mean,size:torch.Size([512])
backbone.layer2.0.downsample.1.running_var,size:torch.Size([512])
backbone.layer2.0.downsample.1.num_batches_tracked,size:torch.Size([])
backbone.layer2.1.conv1.weight,size:torch.Size([128, 512, 1, 1])
backbone.layer2.1.conv2.weight,size:torch.Size([128, 128, 3, 3])
backbone.layer2.1.bn1.weight,size:torch.Size([128])
backbone.layer2.1.bn1.bias,size:torch.Size([128])
backbone.layer2.1.bn1.running_mean,size:torch.Size([128])
backbone.layer2.1.bn1.running_var,size:torch.Size([128])
backbone.layer2.1.bn1.num_batches_tracked,size:torch.Size([])
backbone.layer2.1.bn2.weight,size:torch.Size([128])
backbone.layer2.1.bn2.bias,size:torch.Size([128])
backbone.layer2.1.bn2.running_mean,size:torch.Size([128])
backbone.layer2.1.bn2.running_var,size:torch.Size([128])
backbone.layer2.1.bn2.num_batches_tracked,size:torch.Size([])
backbone.layer2.1.conv3.weight,size:torch.Size([512, 128, 1, 1])
backbone.layer2.1.bn3.weight,size:torch.Size([512])
backbone.layer2.1.bn3.bias,size:torch.Size([512])
backbone.layer2.1.bn3.running_mean,size:torch.Size([512])
backbone.layer2.1.bn3.running_var,size:torch.Size([512])
backbone.layer2.1.bn3.num_batches_tracked,size:torch.Size([])
backbone.layer2.2.conv1.weight,size:torch.Size([128, 512, 1, 1])
backbone.layer2.2.conv2.weight,size:torch.Size([128, 128, 3, 3])
backbone.layer2.2.bn1.weight,size:torch.Size([128])
backbone.layer2.2.bn1.bias,size:torch.Size([128])
backbone.layer2.2.bn1.running_mean,size:torch.Size([128])
backbone.layer2.2.bn1.running_var,size:torch.Size([128])
backbone.layer2.2.bn1.num_batches_tracked,size:torch.Size([])
backbone.layer2.2.bn2.weight,size:torch.Size([128])
backbone.layer2.2.bn2.bias,size:torch.Size([128])
backbone.layer2.2.bn2.running_mean,size:torch.Size([128])
backbone.layer2.2.bn2.running_var,size:torch.Size([128])
backbone.layer2.2.bn2.num_batches_tracked,size:torch.Size([])
backbone.layer2.2.conv3.weight,size:torch.Size([512, 128, 1, 1])
backbone.layer2.2.bn3.weight,size:torch.Size([512])
backbone.layer2.2.bn3.bias,size:torch.Size([512])
backbone.layer2.2.bn3.running_mean,size:torch.Size([512])
backbone.layer2.2.bn3.running_var,size:torch.Size([512])
backbone.layer2.2.bn3.num_batches_tracked,size:torch.Size([])
backbone.layer2.3.conv1.weight,size:torch.Size([128, 512, 1, 1])
backbone.layer2.3.conv2.weight,size:torch.Size([128, 128, 3, 3])
backbone.layer2.3.bn1.weight,size:torch.Size([128])
backbone.layer2.3.bn1.bias,size:torch.Size([128])
backbone.layer2.3.bn1.running_mean,size:torch.Size([128])
backbone.layer2.3.bn1.running_var,size:torch.Size([128])
backbone.layer2.3.bn1.num_batches_tracked,size:torch.Size([])
backbone.layer2.3.bn2.weight,size:torch.Size([128])
backbone.layer2.3.bn2.bias,size:torch.Size([128])
backbone.layer2.3.bn2.running_mean,size:torch.Size([128])
backbone.layer2.3.bn2.running_var,size:torch.Size([128])
backbone.layer2.3.bn2.num_batches_tracked,size:torch.Size([])
backbone.layer2.3.conv3.weight,size:torch.Size([512, 128, 1, 1])
backbone.layer2.3.bn3.weight,size:torch.Size([512])
backbone.layer2.3.bn3.bias,size:torch.Size([512])
backbone.layer2.3.bn3.running_mean,size:torch.Size([512])
backbone.layer2.3.bn3.running_var,size:torch.Size([512])
backbone.layer2.3.bn3.num_batches_tracked,size:torch.Size([])
backbone.layer3.0.conv1.weight,size:torch.Size([256, 512, 1, 1])
backbone.layer3.0.conv2.weight,size:torch.Size([256, 256, 3, 3])
backbone.layer3.0.bn1.weight,size:torch.Size([256])
backbone.layer3.0.bn1.bias,size:torch.Size([256])
backbone.layer3.0.bn1.running_mean,size:torch.Size([256])
backbone.layer3.0.bn1.running_var,size:torch.Size([256])
backbone.layer3.0.bn1.num_batches_tracked,size:torch.Size([])
backbone.layer3.0.bn2.weight,size:torch.Size([256])
backbone.layer3.0.bn2.bias,size:torch.Size([256])
backbone.layer3.0.bn2.running_mean,size:torch.Size([256])
backbone.layer3.0.bn2.running_var,size:torch.Size([256])
backbone.layer3.0.bn2.num_batches_tracked,size:torch.Size([])
backbone.layer3.0.conv3.weight,size:torch.Size([1024, 256, 1, 1])
backbone.layer3.0.bn3.weight,size:torch.Size([1024])
backbone.layer3.0.bn3.bias,size:torch.Size([1024])
backbone.layer3.0.bn3.running_mean,size:torch.Size([1024])
backbone.layer3.0.bn3.running_var,size:torch.Size([1024])
backbone.layer3.0.bn3.num_batches_tracked,size:torch.Size([])
backbone.layer3.0.downsample.0.weight,size:torch.Size([1024, 512, 1, 1])
backbone.layer3.0.downsample.1.weight,size:torch.Size([1024])
backbone.layer3.0.downsample.1.bias,size:torch.Size([1024])
backbone.layer3.0.downsample.1.running_mean,size:torch.Size([1024])
backbone.layer3.0.downsample.1.running_var,size:torch.Size([1024])
backbone.layer3.0.downsample.1.num_batches_tracked,size:torch.Size([])
backbone.layer3.1.conv1.weight,size:torch.Size([256, 1024, 1, 1])
backbone.layer3.1.conv2.weight,size:torch.Size([256, 256, 3, 3])
backbone.layer3.1.bn1.weight,size:torch.Size([256])
backbone.layer3.1.bn1.bias,size:torch.Size([256])
backbone.layer3.1.bn1.running_mean,size:torch.Size([256])
backbone.layer3.1.bn1.running_var,size:torch.Size([256])
backbone.layer3.1.bn1.num_batches_tracked,size:torch.Size([])
backbone.layer3.1.bn2.weight,size:torch.Size([256])
backbone.layer3.1.bn2.bias,size:torch.Size([256])
backbone.layer3.1.bn2.running_mean,size:torch.Size([256])
backbone.layer3.1.bn2.running_var,size:torch.Size([256])
backbone.layer3.1.bn2.num_batches_tracked,size:torch.Size([])
backbone.layer3.1.conv3.weight,size:torch.Size([1024, 256, 1, 1])
backbone.layer3.1.bn3.weight,size:torch.Size([1024])
backbone.layer3.1.bn3.bias,size:torch.Size([1024])
backbone.layer3.1.bn3.running_mean,size:torch.Size([1024])
backbone.layer3.1.bn3.running_var,size:torch.Size([1024])
backbone.layer3.1.bn3.num_batches_tracked,size:torch.Size([])
backbone.layer3.2.conv1.weight,size:torch.Size([256, 1024, 1, 1])
backbone.layer3.2.conv2.weight,size:torch.Size([256, 256, 3, 3])
backbone.layer3.2.bn1.weight,size:torch.Size([256])
backbone.layer3.2.bn1.bias,size:torch.Size([256])
backbone.layer3.2.bn1.running_mean,size:torch.Size([256])
backbone.layer3.2.bn1.running_var,size:torch.Size([256])
backbone.layer3.2.bn1.num_batches_tracked,size:torch.Size([])
backbone.layer3.2.bn2.weight,size:torch.Size([256])
backbone.layer3.2.bn2.bias,size:torch.Size([256])
backbone.layer3.2.bn2.running_mean,size:torch.Size([256])
backbone.layer3.2.bn2.running_var,size:torch.Size([256])
backbone.layer3.2.bn2.num_batches_tracked,size:torch.Size([])
backbone.layer3.2.conv3.weight,size:torch.Size([1024, 256, 1, 1])
backbone.layer3.2.bn3.weight,size:torch.Size([1024])
backbone.layer3.2.bn3.bias,size:torch.Size([1024])
backbone.layer3.2.bn3.running_mean,size:torch.Size([1024])
backbone.layer3.2.bn3.running_var,size:torch.Size([1024])
backbone.layer3.2.bn3.num_batches_tracked,size:torch.Size([])
backbone.layer3.3.conv1.weight,size:torch.Size([256, 1024, 1, 1])
backbone.layer3.3.conv2.weight,size:torch.Size([256, 256, 3, 3])
backbone.layer3.3.bn1.weight,size:torch.Size([256])
backbone.layer3.3.bn1.bias,size:torch.Size([256])
backbone.layer3.3.bn1.running_mean,size:torch.Size([256])
backbone.layer3.3.bn1.running_var,size:torch.Size([256])
backbone.layer3.3.bn1.num_batches_tracked,size:torch.Size([])
backbone.layer3.3.bn2.weight,size:torch.Size([256])
backbone.layer3.3.bn2.bias,size:torch.Size([256])
backbone.layer3.3.bn2.running_mean,size:torch.Size([256])
backbone.layer3.3.bn2.running_var,size:torch.Size([256])
backbone.layer3.3.bn2.num_batches_tracked,size:torch.Size([])
backbone.layer3.3.conv3.weight,size:torch.Size([1024, 256, 1, 1])
backbone.layer3.3.bn3.weight,size:torch.Size([1024])
backbone.layer3.3.bn3.bias,size:torch.Size([1024])
backbone.layer3.3.bn3.running_mean,size:torch.Size([1024])
backbone.layer3.3.bn3.running_var,size:torch.Size([1024])
backbone.layer3.3.bn3.num_batches_tracked,size:torch.Size([])
backbone.layer3.4.conv1.weight,size:torch.Size([256, 1024, 1, 1])
backbone.layer3.4.conv2.weight,size:torch.Size([256, 256, 3, 3])
backbone.layer3.4.bn1.weight,size:torch.Size([256])
backbone.layer3.4.bn1.bias,size:torch.Size([256])
backbone.layer3.4.bn1.running_mean,size:torch.Size([256])
backbone.layer3.4.bn1.running_var,size:torch.Size([256])
backbone.layer3.4.bn1.num_batches_tracked,size:torch.Size([])
backbone.layer3.4.bn2.weight,size:torch.Size([256])
backbone.layer3.4.bn2.bias,size:torch.Size([256])
backbone.layer3.4.bn2.running_mean,size:torch.Size([256])
backbone.layer3.4.bn2.running_var,size:torch.Size([256])
backbone.layer3.4.bn2.num_batches_tracked,size:torch.Size([])
backbone.layer3.4.conv3.weight,size:torch.Size([1024, 256, 1, 1])
backbone.layer3.4.bn3.weight,size:torch.Size([1024])
backbone.layer3.4.bn3.bias,size:torch.Size([1024])
backbone.layer3.4.bn3.running_mean,size:torch.Size([1024])
backbone.layer3.4.bn3.running_var,size:torch.Size([1024])
backbone.layer3.4.bn3.num_batches_tracked,size:torch.Size([])
backbone.layer3.5.conv1.weight,size:torch.Size([256, 1024, 1, 1])
backbone.layer3.5.conv2.weight,size:torch.Size([256, 256, 3, 3])
backbone.layer3.5.bn1.weight,size:torch.Size([256])
backbone.layer3.5.bn1.bias,size:torch.Size([256])
backbone.layer3.5.bn1.running_mean,size:torch.Size([256])
backbone.layer3.5.bn1.running_var,size:torch.Size([256])
backbone.layer3.5.bn1.num_batches_tracked,size:torch.Size([])
backbone.layer3.5.bn2.weight,size:torch.Size([256])
backbone.layer3.5.bn2.bias,size:torch.Size([256])
backbone.layer3.5.bn2.running_mean,size:torch.Size([256])
backbone.layer3.5.bn2.running_var,size:torch.Size([256])
backbone.layer3.5.bn2.num_batches_tracked,size:torch.Size([])
backbone.layer3.5.conv3.weight,size:torch.Size([1024, 256, 1, 1])
backbone.layer3.5.bn3.weight,size:torch.Size([1024])
backbone.layer3.5.bn3.bias,size:torch.Size([1024])
backbone.layer3.5.bn3.running_mean,size:torch.Size([1024])
backbone.layer3.5.bn3.running_var,size:torch.Size([1024])
backbone.layer3.5.bn3.num_batches_tracked,size:torch.Size([])
backbone.layer4.0.conv1.weight,size:torch.Size([512, 1024, 1, 1])
backbone.layer4.0.conv2.weight,size:torch.Size([512, 512, 3, 3])
backbone.layer4.0.bn1.weight,size:torch.Size([512])
backbone.layer4.0.bn1.bias,size:torch.Size([512])
backbone.layer4.0.bn1.running_mean,size:torch.Size([512])
backbone.layer4.0.bn1.running_var,size:torch.Size([512])
backbone.layer4.0.bn1.num_batches_tracked,size:torch.Size([])
backbone.layer4.0.bn2.weight,size:torch.Size([512])
backbone.layer4.0.bn2.bias,size:torch.Size([512])
backbone.layer4.0.bn2.running_mean,size:torch.Size([512])
backbone.layer4.0.bn2.running_var,size:torch.Size([512])
backbone.layer4.0.bn2.num_batches_tracked,size:torch.Size([])
backbone.layer4.0.conv3.weight,size:torch.Size([2048, 512, 1, 1])
backbone.layer4.0.bn3.weight,size:torch.Size([2048])
backbone.layer4.0.bn3.bias,size:torch.Size([2048])
backbone.layer4.0.bn3.running_mean,size:torch.Size([2048])
backbone.layer4.0.bn3.running_var,size:torch.Size([2048])
backbone.layer4.0.bn3.num_batches_tracked,size:torch.Size([])
backbone.layer4.0.downsample.0.weight,size:torch.Size([2048, 1024, 1, 1])
backbone.layer4.0.downsample.1.weight,size:torch.Size([2048])
backbone.layer4.0.downsample.1.bias,size:torch.Size([2048])
backbone.layer4.0.downsample.1.running_mean,size:torch.Size([2048])
backbone.layer4.0.downsample.1.running_var,size:torch.Size([2048])
backbone.layer4.0.downsample.1.num_batches_tracked,size:torch.Size([])
backbone.layer4.1.conv1.weight,size:torch.Size([512, 2048, 1, 1])
backbone.layer4.1.conv2.weight,size:torch.Size([512, 512, 3, 3])
backbone.layer4.1.bn1.weight,size:torch.Size([512])
backbone.layer4.1.bn1.bias,size:torch.Size([512])
backbone.layer4.1.bn1.running_mean,size:torch.Size([512])
backbone.layer4.1.bn1.running_var,size:torch.Size([512])
backbone.layer4.1.bn1.num_batches_tracked,size:torch.Size([])
backbone.layer4.1.bn2.weight,size:torch.Size([512])
backbone.layer4.1.bn2.bias,size:torch.Size([512])
backbone.layer4.1.bn2.running_mean,size:torch.Size([512])
backbone.layer4.1.bn2.running_var,size:torch.Size([512])
backbone.layer4.1.bn2.num_batches_tracked,size:torch.Size([])
backbone.layer4.1.conv3.weight,size:torch.Size([2048, 512, 1, 1])
backbone.layer4.1.bn3.weight,size:torch.Size([2048])
backbone.layer4.1.bn3.bias,size:torch.Size([2048])
backbone.layer4.1.bn3.running_mean,size:torch.Size([2048])
backbone.layer4.1.bn3.running_var,size:torch.Size([2048])
backbone.layer4.1.bn3.num_batches_tracked,size:torch.Size([])
backbone.layer4.2.conv1.weight,size:torch.Size([512, 2048, 1, 1])
backbone.layer4.2.conv2.weight,size:torch.Size([512, 512, 3, 3])
backbone.layer4.2.bn1.weight,size:torch.Size([512])
backbone.layer4.2.bn1.bias,size:torch.Size([512])
backbone.layer4.2.bn1.running_mean,size:torch.Size([512])
backbone.layer4.2.bn1.running_var,size:torch.Size([512])
backbone.layer4.2.bn1.num_batches_tracked,size:torch.Size([])
backbone.layer4.2.bn2.weight,size:torch.Size([512])
backbone.layer4.2.bn2.bias,size:torch.Size([512])
backbone.layer4.2.bn2.running_mean,size:torch.Size([512])
backbone.layer4.2.bn2.running_var,size:torch.Size([512])
backbone.layer4.2.bn2.num_batches_tracked,size:torch.Size([])
backbone.layer4.2.conv3.weight,size:torch.Size([2048, 512, 1, 1])
backbone.layer4.2.bn3.weight,size:torch.Size([2048])
backbone.layer4.2.bn3.bias,size:torch.Size([2048])
backbone.layer4.2.bn3.running_mean,size:torch.Size([2048])
backbone.layer4.2.bn3.running_var,size:torch.Size([2048])
backbone.layer4.2.bn3.num_batches_tracked,size:torch.Size([])
cls_head.fc_cls.weight,size:torch.Size([101, 2048])
cls_head.fc_cls.bias,size:torch.Size([101])
pytorch:如何修改加载了预训练权重的模型的输入或输出–(生成新的权重文件)