open-mmlab / mmsegmentation

OpenMMLab Semantic Segmentation Toolbox and Benchmark.
https://mmsegmentation.readthedocs.io/en/main/
Apache License 2.0
7.73k stars 2.53k forks source link

how to use the file:analysis_tools/visualization_cam.py,when i use it in segformer,occur error #3369

Open OpenAI-chn opened 9 months ago

OpenAI-chn commented 9 months ago

this is my code,I want to use it in segformer, so i add the reshape_transform:

analysis_tools/visualization_cam.py:

with GradCAM(
        model=model,
        target_layers=target_layers,
        use_cuda=torch.cuda.is_available(),
       reshape_transform=reshape_transform) as cam:

    grayscale_cam = cam(input_tensor=input_tensor, targets=targets)[0, :]

    cam_image = show_cam_on_image(rgb_img, grayscale_cam, use_rgb=True)

but it does not work,occur below: An exception occurred in CAM with block: <class 'numpy.AxisError'>. Message: axis 2 is out of bounds for array of dimension 0

DariiaKhoroshchuk commented 7 months ago

Hi! Have you managed to fix that? If so, could you let me know what the issue was and how you resolved it?

OpenAI-chn commented 7 months ago

没有,暂时放弃了使用这个功能,以后我慢慢研究,我知道了回来告诉你哈