关于CAM热力图报错:AttributeError: ‘GradCAMPlusPlus‘ object has no attribute ‘activations_and_grads‘

报错信息如下(错误的关键已用红色标出):

Traceback (most recent call last):
  File "D:\langsongsong\file\pytorch-classifier-master\predict.py", line 71, in <module>
    cam_model = cam_visual(model, test_transform, DEVICE, opt)
  File "D:\langsongsong\file\pytorch-classifier-master\utils\utils.py", line 664, in __init__
    self.cam_model = eval(opt.cam_type)(model=model, target_layers=model.cam_layer(), use_cuda=(DEVICE.type != 'cpu'))
  File "C:\Users\langsongsong\AppData\Roaming\Python\Python39\site-packages\pytorch_grad_cam\grad_cam_plusplus.py", line 10, in __init__
    super(GradCAMPlusPlus, self).__init__(model, target_layers, use_cuda,
  File "C:\Users\langsongsong\AppData\Roaming\Python\Python39\site-packages\pytorch_grad_cam\base_cam.py", line 27, in __init__
    self.activations_and_grads = ActivationsAndGradients(
  File "C:\Users\langsongsong\AppData\Roaming\Python\Python39\site-packages\pytorch_grad_cam\activations_and_gradients.py", line 11, in __init__
    for target_layer in target_layers:
TypeError: 'Hardswish' object is not iterable
Exception ignored in: <function BaseCAM.__del__ at 0x0000022B7113A160>
Traceback (most recent call last):
  File "C:\Users\langsongsong\AppData\Roaming\Python\Python39\site-packages\pytorch_grad_cam\base_cam.py", line 192, in __del__
    self.activations_and_grads.release()
AttributeError: 'GradCAMPlusPlus' object has no attribute 'activations_and_grads'

修改如下:
self.cam_model = eval(opt.cam_type)(model=model, target_layers=[model.cam_layer()], use_cuda=(DEVICE.type != 'cpu'))

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值