Pytorch中的VGG实现修改最后一层FC

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

Pytorch中的VGG实现修改最后一层FC

  2021-04-02 我要评论

https://discuss.pytorch.org/t/how-to-modify-the-final-fc-layer-based-on-the-torch-model/766/12

That's because vgg19 doesn't have a fc member variable. Instead, it has a

 (classifier): Sequential (
 (0): Dropout (p = 0.5)
 (1): Linear (25088 -> 4096)
 (2): ReLU (inplace)
 (3): Dropout (p = 0.5)
 (4): Linear (4096 -> 4096)
 (5): ReLU (inplace)
 (6): Linear (4096 -> 100)
 )

To replace the last linear layer, a temporary solution would be

vgg19.classifier._modules['6'] = nn.Linear(4096, 8)

以上这篇Pytorch中的VGG实现修改最后一层FC就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。

您可能感兴趣的文章:

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们