python报错: RuntimeError: Error(s) in loading state_dict for ResNet:size mismatch for conv1.weight: ..

 首先在此之前,你可能已经见到过各种和CUDA有关的错误,比如:

1、CUDA error: CUBLAS_STATUS_NOT_INITIALIZED when calling `cublasCreate(handle)`

2、RuntimeError: CUDA error: device-side assert triggered CUDA kernel errors might be asynchronously reported at some other API call, so the stacktrace below might be incorrect. For debugging consider passing CUDA_LAUNCH_BLOCKING=1. Compile with `TORCH_USE_CUDA_DSA` to enable device-side assertions.

这些不管能不能看懂,强烈建议先换成cpu再跑一遍,显示出真实的错误原因。

#device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')
device = torch.device('cpu')

 可见报错是因为加载参数过程中出现的错误,权重的size不匹配:

比如我这里是加载了一个resnet的预训练模型,但是从网上下载的时候把3D的模型下成了2D的,可以看到参数少了一个维度,重新下载之后就解决啦。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值