TypeError: GradCAM.__init__() got an unexpected keyword argument ‘use_cuda‘

在尝试使用mmpretrain的vis_cam.py生成热力图时遇到TypeError,因为use_cuda参数未被正确使用。修复方法是删除该参数,直接实例化GradCAM类。删除后,程序可以正常运行并输出热力图。
摘要由CSDN通过智能技术生成

学习mmpretrain,运行tools/visualization/vis_cam.py输出热力图,遇到报错TypeError: GradCAM.__init__() got an unexpected keyword argument 'use_cuda'。

报错定位到vis_cam.py文件:

def init_cam(method, model, target_layers, use_cuda, reshape_transform):
    """Construct the CAM object once, In order to be compatible with
    mmpretrain, here we modify the ActivationsAndGradients object."""
    GradCAM_Class = METHOD_MAP[method.lower()]
    cam = GradCAM_Class(
        model=model, target_layers=target_layers, use_cuda=use_cuda)

最后两行进行了赋值use_cuda = use_cuda,但实际上并没有使用这个变量,直接删掉即可:

 cam = GradCAM_Class(
         model=model, target_layers=target_layers)

随后可以正常运行,输出热力图:

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值