官网:https://meclabtuda.github.io/M3d-Cam/medcam/medcam_inject.html
Github网址:https://github.com/MECLabTUDA/M3d-Cam
安装可直运行:
pip install medcam
# 或者
conda install -c conda-forge medcam
例子代码:
# Import M3d-CAM
from medcam import medcam
# Init your model and dataloader
model = MyCNN()
data_loader = DataLoader(dataset, batch_size=1, shuffle=False)
# Inject model with M3d-CAM
model = medcam.inject(model, output_dir="attention_maps", save_maps=True)
# Continue to do what you're doing...
# In this case inference on some new data
model.eval()
for batch in data_loader:
# Every time forward is called, attention maps will be generated and saved in the directory "attention_maps"
output = model(batch)
# more of your code...
结果展示: