我正在使用 resnet 进行多类分类制作深度学习模型,在其中我面临着过度拟合的问题。为了解决这个问题,我尝试减少 resnet 的层数,但我遇到了这个错误
运行时错误:mat1 和 mat2 形状无法相乘(65536x1 和 2048x1000)
我的代码是
class Flowers(nn.Module):
def __init__(self):
super().__init__()
self.classifier=nn.Sequential(
nn.Flatten(),nn.Linear(in_features=1,out_features=102),
)
def forward(self,x):
x=self.classifier(x)
return x
torch.manual_seed(42)
model = torch.hub.load("pytorch/vision", "resnet50", weights="IMAGENET1K_V2")
list(model.modules())
my_model = nn.Sequential(*list(model.children())[:12])
my_model.add_module('fc', Flowers())
如果有人能帮助我解决一般的过度拟合问题,那将是巨大的帮助。