用pytorch加载训练模型
生活随笔
收集整理的這篇文章主要介紹了
用pytorch加载训练模型
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
用pytorch加載.pth格式的訓練模型
在pytorch/vision/models網頁上有很多現成的經典網絡模型可以調用,其中包括alexnet、vgg、googlenet、resnet、inception、densenet、mobilenet等。把模型下載下來之后,打開模型查看網絡模型里面的具體內容內容是什么。
以resnet101為例,查看它里面定義了網絡的哪些參數。
有時候用以上代碼打開訓練模型的時候可能會提示Runtime Error,修改加載模型部分的代碼為
net.load_state_dict(torch.load(checkpoint), False)可以看到resnet101.pth的定義的模型結構和參數如下,包括卷積層的卷積核大小、層數、滑動步長、激活函數、池化函數、隨機失活(dropout)的概率等信息。
Parameters of resnet101: SqueezeNet((features): Sequential((0): Conv2d(3, 64, kernel_size=(3, 3), stride=(2, 2))(1): ReLU(inplace=True)(2): MaxPool2d(kernel_size=3, stride=2, padding=0, dilation=1, ceil_mode=True)(3): Fire((squeeze): Conv2d(64, 16, kernel_size=(1, 1), stride=(1, 1))(squeeze_activation): ReLU(inplace=True)(expand1x1): Conv2d(16, 64, kernel_size=(1, 1), stride=(1, 1))(expand1x1_activation): ReLU(inplace=True)(expand3x3): Conv2d(16, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))(expand3x3_activation): ReLU(inplace=True))(4): Fire((squeeze): Conv2d(128, 16, kernel_size=(1, 1), stride=(1, 1))(squeeze_activation): ReLU(inplace=True)(expand1x1): Conv2d(16, 64, kernel_size=(1, 1), stride=(1, 1))(expand1x1_activation): ReLU(inplace=True)(expand3x3): Conv2d(16, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))(expand3x3_activation): ReLU(inplace=True))(5): MaxPool2d(kernel_size=3, stride=2, padding=0, dilation=1, ceil_mode=True)(6): Fire((squeeze): Conv2d(128, 32, kernel_size=(1, 1), stride=(1, 1))(squeeze_activation): ReLU(inplace=True)(expand1x1): Conv2d(32, 128, kernel_size=(1, 1), stride=(1, 1))(expand1x1_activation): ReLU(inplace=True)(expand3x3): Conv2d(32, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))(expand3x3_activation): ReLU(inplace=True))(7): Fire((squeeze): Conv2d(256, 32, kernel_size=(1, 1), stride=(1, 1))(squeeze_activation): ReLU(inplace=True)(expand1x1): Conv2d(32, 128, kernel_size=(1, 1), stride=(1, 1))(expand1x1_activation): ReLU(inplace=True)(expand3x3): Conv2d(32, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))(expand3x3_activation): ReLU(inplace=True))(8): MaxPool2d(kernel_size=3, stride=2, padding=0, dilation=1, ceil_mode=True)(9): Fire((squeeze): Conv2d(256, 48, kernel_size=(1, 1), stride=(1, 1))(squeeze_activation): ReLU(inplace=True)(expand1x1): Conv2d(48, 192, kernel_size=(1, 1), stride=(1, 1))(expand1x1_activation): ReLU(inplace=True)(expand3x3): Conv2d(48, 192, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))(expand3x3_activation): ReLU(inplace=True))(10): Fire((squeeze): Conv2d(384, 48, kernel_size=(1, 1), stride=(1, 1))(squeeze_activation): ReLU(inplace=True)(expand1x1): Conv2d(48, 192, kernel_size=(1, 1), stride=(1, 1))(expand1x1_activation): ReLU(inplace=True)(expand3x3): Conv2d(48, 192, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))(expand3x3_activation): ReLU(inplace=True))(11): Fire((squeeze): Conv2d(384, 64, kernel_size=(1, 1), stride=(1, 1))(squeeze_activation): ReLU(inplace=True)(expand1x1): Conv2d(64, 256, kernel_size=(1, 1), stride=(1, 1))(expand1x1_activation): ReLU(inplace=True)(expand3x3): Conv2d(64, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))(expand3x3_activation): ReLU(inplace=True))(12): Fire((squeeze): Conv2d(512, 64, kernel_size=(1, 1), stride=(1, 1))(squeeze_activation): ReLU(inplace=True)(expand1x1): Conv2d(64, 256, kernel_size=(1, 1), stride=(1, 1))(expand1x1_activation): ReLU(inplace=True)(expand3x3): Conv2d(64, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))(expand3x3_activation): ReLU(inplace=True)))(classifier): Sequential((0): Dropout(p=0.5, inplace=False)(1): Conv2d(512, 1000, kernel_size=(1, 1), stride=(1, 1))(2): ReLU(inplace=True)(3): AdaptiveAvgPool2d(output_size=(1, 1))) )總結
以上是生活随笔為你收集整理的用pytorch加载训练模型的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 颉伟/郭勇/李伟合作阐释哺乳动物早期胚胎
- 下一篇: 图像入门二之视频操作