EfficientNet에 대한 CAM 적용 여부 및 대안

원조 CAM(Class Activation Map)은 “마지막 합성곱층 → Global Average Pooling(GAP) → FC” 구조에서만 직접 적용 가능하다. EfficientNet도 내부적으로는

… → conv_head → AdaptiveAvgPool2d → Dropout → Linear(classifier)

와 같은 구조를 가지므로, 이론상 conv_head의 출력(feature map)과 classifier의 가중치를 이용해 CAM을 계산할 수 있다. 다만 원조 CAM을 쓰려면

  • 모델을 GAP+FC 구조로 재학습하거나,
  • Dropout 등 classifier 직전의 layer를 제거·변경해야 하는 번거로움이 있다[1].

따라서 일반적으로는 Grad-CAM이나 Score-CAM과 같은 후속 기법을 활용한다. 이들은 모델 구조 수정 없이도 마지막 합성곱층(즉 model.conv_head)만 지정하면 바로 적용 가능하다[1][2]. 특히:

  • PyTorch용 pytorch-grad-cam 라이브러리
    target_layers=[model.conv_head] 로 지정
    – Swish 활성화 함수도 자동 처리
  • Captum의 GuidedGradCam
    – EfficientNet은 Swish를 쓰므로, GuidedBackPropagationSwish로 교체 후 사용[3].

이처럼 EfficientNet에도 CAM 계열 시각화 기법(Grad-CAM, Score-CAM 등)을 모델 수정 없이 적용할 수 있으니, 원조 CAM만 가능 여부에 얽매이지 말고 후속 기법을 활용하는 것을 권장한다.

출처
[1] Pytorch, grad-cam 사용 정리 – Honbul과 컴퓨터 – 티스토리 https://honbul.tistory.com/54
[2] yaleCat/Grad-CAM-pytorch – GitHub https://github.com/yaleCat/Grad-CAM-pytorch
[3] GuidedGradCam on EfficientNet – Captum – PyTorch Forums https://discuss.pytorch.org/t/guidedgradcam-on-efficientnet/111035
[4] EfficientNet : Rethinking Model Scaling for Convolutional Neural … https://ropiens.tistory.com/110
[5] EfficientNet – velog https://velog.io/@tjddls321/EfficientNet
[6] [PDF] Smoothed Score-CAM for Sharper Visual Feature Localization – arXiv https://arxiv.org/pdf/2006.14255.pdf
[7] [논문 리뷰 및 구현] EfficientNet 구현 – velog https://velog.io/@krec7748/Pytorch-EfficientNet-%EA%B5%AC%ED%98%84
[8] sidml/EfficientNet-GradCam-Visualization – GitHub https://github.com/sidml/EfficientNet-GradCam-Visualization
[9] Problems with EfficientNet · Issue #32 · kazuto1011/grad-cam-pytorch https://github.com/kazuto1011/grad-cam-pytorch/issues/32
[10] How to obtain the last convolutional layer of a model in torchvision … https://stats.stackexchange.com/questions/629352/how-to-obtain-the-last-convolutional-layer-of-a-model-in-torchvision-for-applyin
[11] [Question] How to implement Grad-CAM for effnetv2 model #1111 https://github.com/google/automl/issues/1111
[12] How to obtain the last convolucional layer of a visiontorch model? https://discuss.pytorch.org/t/how-to-obtain-the-last-convolucional-layer-of-a-visiontorch-model/190418
[13] GradCAM: Enhancing Neural Network Interpretability – LearnOpenCV https://learnopencv.com/intro-to-gradcam/
[14] Grad-CAM class activation visualization – Keras https://keras.io/examples/vision/grad_cam/
[15] a grad-CAM visualization approach – PMC – PubMed Central https://pmc.ncbi.nlm.nih.gov/articles/PMC11683681/
[16] Grad-CAM: The impact of large receptive fields and other caveats https://www.sciencedirect.com/science/article/abs/pii/S1077314225001067
[17] Grad-CAM: Visualizing What Your Neural Network Sees – AI Mind https://pub.aimind.so/grad-cam-visualizing-what-your-neural-network-sees-3fec8a800afd
[18] Issues with applying GradCam on this implementation #184 – GitHub https://github.com/lukemelas/EfficientNet-PyTorch/issues/184
[19] Grad-CAM Reveals the Why Behind Deep Learning Decisions https://kr.mathworks.com/help/deeplearning/ug/gradcam-explains-why.html
[20] EfficientNetB0 colab에서 pytorch로 구현해서 CIFAR-10 학습시켜보기 https://startnow95.tistory.com/4
[21] [5분 컷 이해] Grad-CAM 의 이해 – 연금술사 https://analytics4everything.tistory.com/224
[22] [PDF] Brain Tumor Classification with Optimized EfficientNet Architecture https://www.jneonatalsurg.com/index.php/jns/article/download/3990/3501/16237
[23] [PDF] EVALUATING EXPLAINABLE AI METHODS IN DEEP LEARNING … https://arxiv.org/pdf/2409.0001.pdf
[24] TF: Hybrid EfficientNet Swin-Transformer : GradCAM – Kaggle https://www.kaggle.com/code/ipythonx/tf-hybrid-efficientnet-swin-transformer-gradcam
[25] EfficientNet – 홍러닝 – 티스토리 https://hongl.tistory.com/70
[26] How to implement GradCAM on a trained network – pytorch https://stackoverflow.com/questions/72433403/how-to-implement-gradcam-on-a-trained-network-pytorch
[27] TF: Hybrid EfficientNet Swin-Transformer : GradCAM – Kaggle https://www.kaggle.com/code/channingfisher/tf-hybrid-efficientnet-swin-transformer-gradcam
[28] [PDF] Deep learning resting state fMRI lateralization of temporal lobe … https://dosenbachlab.wustl.edu/media/papers/Epilepsia-2022-Luckett-Deep_learning_resting_state_fMRI_lateralization_of_tempora_oJxHOal.pdf

코멘트

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다