[英]size mismatch for linear.weight and linear.bias in Torch model
我正在使用以下代碼加載 model。
model.to(device)
checkpoint = torch.load("weights/vgg.pth")
if 'state_dict' in checkpoint:
checkpoint = checkpoint['state_dict']
ckpt = {k.replace('module.', ''):v for k,v in checkpoint.items()}
model.load_state_dict(ckpt)
我收到錯誤消息:
self.__class__.__name__, "\n\t".join(error_msgs))) RuntimeError: Error(s) in loading state_dict for RepVGG: size mismatch for linear.weight: copying a param with shape torch.Size([1000, 1280]) from checkpoint, the shape in current model is torch.Size([8, 1280]). size mismatch for linear.bias: copying a param with shape torch.Size([1000]) from checkpoint, the shape in current model is torch.Size([8]).
您當前的 model 似乎配置為提供 8 個類別的分類( num_class=8
)。 但是,您正在加載的檢查點是在具有 1000 個類的 ImageNet 上預訓練的 VGG model。 因此,最后一層的權重和偏差的維度不匹配。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.