标准mobilenet运行报错(resnet18没问题)
来源:6-14 PyTorch搭建cifar10训练脚本搭建-调用Pytorch标准网络ResNet18等

慕勒1019045
2021-10-30
import torch.nn as nn
from torchvision import models
class mobilenet_v2(nn.Module):
def __init__(self):
super(mobilenet_v2, self).__init__()
self.model = models.mobilenet_v2(pretrained=True)
# self.num_features = self.model.fc.in_features
self.num_features = self.model.fc.in_features
self.model.fc = nn.Linear(self.num_features, 10)
def forward(self, x):
out = self.model(x)
return out
def pytorch_mobilenet_v2():
return mobilenet_v2()
net = pytorch_mobilenet_v2().to(device)
写回答
1回答
-
会写代码的好厨师
2021-12-01
看报错是mobilenetv2没有fc层,可以尝试把mobile netv2的网络结构打印出来,看一下最后一层是什么,然后进行相应的调整
00
相似问题