pytorch 修改预训练model实例
程序员文章站
2023-11-25 13:50:28
我就废话不多说了,直接上代码吧!
class net(nn.module):
def __init__(self , model):
super(net, s...
我就废话不多说了,直接上代码吧!
class net(nn.module): def __init__(self , model): super(net, self).__init__() #取掉model的后两层 self.resnet_layer = nn.sequential(*list(model.children())[:-2]) self.transion_layer = nn.convtranspose2d(2048, 2048, kernel_size=14, stride=3) self.pool_layer = nn.maxpool2d(32) self.linear_layer = nn.linear(2048, 8) def forward(self, x): x = self.resnet_layer(x) x = self.transion_layer(x) x = self.pool_layer(x) x = x.view(x.size(0), -1) x = self.linear_layer(x) return x
resnet = models.resnet50(pretrained=true) model = net(resnet)
以上这篇pytorch 修改预训练model实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。