1.背景描述
想借助一个预训练好的网络(非集成好的)计算feature-loss,预训练网络地址:表情识别net
2具体实操
2.1 加载模型
作者已经给出了预训练好的模型参数和模型代码,首先我们要把模型load进来:
from Expression.VGG import VGG
model = VGG('VGG19')
#check_pth 从网站上download下来PrivateTest_model.t7
checkpoint = torch.load(check_pth)
model.load_state_dict(checkpoint['net'])
model.cuda()
model.eval()
我们可以看一下该模型的结构
print(torch.nn.Sequential(*list(model.children())[:]))
结果为:
Sequential(
(0): Sequential(
(0): Conv2d(3, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
(1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(2): ReLU(inplace)
(3): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
(4): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(5): ReLU(inplace)
(6): MaxPool2d(kernel_size=2, stride=2, padding=0, dilation=1, ceil_mode=False)
(7): Conv2d(64, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
(8): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(9): ReLU(inplace)
(10): Conv2d(128, 128