Giter VIP home page Giter VIP logo

fitushar / 3d-guidedgradcam-for-medical-imaging Goto Github PK

View Code? Open in Web Editor NEW
91.0 2.0 8.0 629 KB

This Repo containes the implemnetation of generating Guided-GradCAM for 3D medical Imaging using Nifti file in tensorflow 2.0. Different input files can be used in that case need to edit the input to the Guided-gradCAM model.

Python 100.00%
guided-grad-cam 3d-guided-grad-cam tensorflow-examples 3d-models cnn-visualization cnn-visualization-technique nifti ctci tensorflow2 medical-imaging

3d-guidedgradcam-for-medical-imaging's Introduction

3D-GuidedGradCAM-for-Medical-Imaging

This Repo containes the implemnetation of generating Guided-GradCAM for 3D medical Imaging using Nifti file in tensorflow 2.0. Different input files can be used in that case need to edit the input to the Guided-gradCAM model.

Files:

   i) guided_Gradcam3D.py         |--> Generate Guided-GradCAM , input and output nifti data
  ii) Guided_GradCAM_3D_config.py |--> Configuration file for the Guided-GradCAM, Modify based on your need
 iii) Resnet_3D.py                |--> Network architecture
  iv) deploy_config.py               |--> Configuration file for the Network, Modify based on your need
   v) loss_funnction_And_matrics.py  |--> Loss functions for CNN

How to run

To run and generate Guided-GardCAM all is to need to configure the Guided_GradCAM_3D_config.py and deploy_config.py based on your requiremnet.

deploy_config.py-

CNN configuration Change based on your Network or complete replace by your CNN

import tensorflow as tf
import math
from loss_funnction_And_matrics import*
###---Number-of-GPU
NUM_OF_GPU=1
DISTRIIBUTED_STRATEGY_GPUS=["gpu:0","gpu:1","gpu:2"]
##Network Configuration
NUMBER_OF_CLASSES=5
INPUT_PATCH_SIZE=(224,160,160, 1)
TRAIN_NUM_RES_UNIT=3
TRAIN_NUM_FILTERS=(16, 32, 64, 128)
TRAIN_STRIDES=((1, 1, 1), (2, 2, 2), (2, 2, 2), (2, 2, 2))
TRAIN_CLASSIFY_ACTICATION=tf.nn.relu6
TRAIN_KERNAL_INITIALIZER=tf.keras.initializers.VarianceScaling(distribution='uniform')
TRAIN_CLASSIFY_LEARNING_RATE =1e-4
TRAIN_CLASSIFY_LOSS=Weighted_BCTL
OPTIMIZER=tf.keras.optimizers.Adam(lr=TRAIN_CLASSIFY_LEARNING_RATE,epsilon=1e-5)
TRAIN_CLASSIFY_METRICS=tf.keras.metrics.AUC()

Guided_GradCAM_3D_config.py

Input Configuration for the Guided-GradCAM

MODEL_WEIGHT="Path/of/Model/Weight/XXX.h5"
CLASS_INDEX=1 # Index of the class for which you want to see the Guided-gradcam
INPUT_PATCH_SIZE_SLICE_NUMBER=64 # Input patch slice you want to feed at a time
LAYER_NAME='conv3d_18' # Name of the layer from where you want to get the Guided-GradCAM
NIFTI_PATH="imput/niftidata/path/XXX.nii.gz"
SAVE_PATH="/Output/niftydata/path/ML_Guided_GradCaN_XXXX.nii.gz"

Sample Guided-GardCAM

SAMPLE Guided-GradCAM1 SAMPLE Guided-GradCAM2 SAMPLE Guided-GradCAM3

3d-guidedgradcam-for-medical-imaging's People

Contributors

fitushar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

3d-guidedgradcam-for-medical-imaging's Issues

Not getting unique heatmap for every slice in input volume

I found the issue. It is due to the resizing of the cam variable using skimage.transform.resize().

from skimage.transform import resize
capi=resize(cam,(128,128,128))

This resizing implementation results in cam[ : , : , 0 ] equalling cam[ : , : , 1 ] and cam[ : , : , -1 ] equalling cam[ : , : , -2] for me.

Swapping the resizing function which relies on scipy.ndimage.zoom()) worked for me.
Now each slice now is unique.

def resize_volume(img, desired_depth, desired_height, desired_width):
"""Resize across z-axis"""

Get current depth

current_depth = img.shape[-1]
current_width = img.shape[0]
current_height = img.shape[1]

Compute depth factor

depth = current_depth / desired_depth
width = current_width / desired_width
height = current_height / desired_height
depth_factor = 1 / depth
width_factor = 1 / width
height_factor = 1 / height

Rotate

img = ndimage.rotate(img, 90, reshape=False)

Resize across z-axis

img = ndimage.zoom(img, (width_factor, height_factor, depth_factor), order=1)
return img

capi = resize_volume(cam,128,128,128)

relevant file = guided_Gradcam3.py

About dataset, pre trained weights and sample images.

Hi! Thanks for sharing your great work! Now I want to train the model. Could you please provide me with some examples for program operation? Includes pretrained weights and sample images. In addition, could you please provide relevant datasets? Thank you very much and look forward to your reply!

ValueError: not enough values to unpack (expected 2, got 1)

Hello, I am trying to apply the gradcam inspired by your code to my resnet3D model.
I keep getting error while calculating the Gradients in the following line :

conv_outputs, predictions = grad_model(input_pet_io)

error:
ValueError: not enough values to unpack (expected 2, got 1)

I want to know why and how exactly conv_outputs is used in this line ?

thank you ~

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.