BioExp.spatial package¶
Submodules¶
BioExp.spatial.ablation module¶
-
class
BioExp.spatial.ablation.
Ablate
(model, weights_pth, metric, layer_name, test_image, gt, classes, nclasses=4, image_name=None)[source]¶ Bases:
object
A class for conducting an ablation study on a trained keras model instance
-
ablate_filters
(filters_to_ablate=None, concept='random', step=None, save_path=None, verbose=1)[source]¶ Drops individual weights from the model, makes the prediction for the test image, and calculates the difference in the evaluation metric as compared to the non- ablated case. For example, for a layer with a weight matrix of shape 3x3x64, individual 3x3 matrices are zeroed out at the interval given by the step argument.
Arguments: step: The interval at which to drop weights Outputs: A dataframe containing the importance scores for each individual weight matrix in the layer
-
BioExp.spatial.dissection module¶
-
class
BioExp.spatial.dissection.
Dissector
(model, layer_name, seq=None)[source]¶ Bases:
object
Network Dissection analysis
model : keras model initialized with trained weights layer_name : intermediate layer name which needs to be analysed
-
apply_threshold
(image, threshold_maps, nfeatures=None, save_path=None, post_process_threshold=80, ROI=None)[source]¶ apply thresholded mask and saves the feature maps for specific iamge
image: test image (Hx W xC) thresholded_maps: threshold maps used for dissection nfeatures : number of features to visualize
all if None- save_path : if None just displayes image else saves feature maps in
- given path
post_process_threshold: threshold for postprocessing cc analysis ROI : region of interest mask in a given image
-
get_threshold_maps
(dataset_path, save_path, percentile, loader=None)[source]¶ Estimates threshold maps for given percentile value
dataset_path: input dataset path save_path : path to save feature maps
if fmaps exists already it directly loads- percentile : value used for thresholding obtained feature maps
- range: (0, 100)
-
quantify_gt_features
(image, gt, threshold_maps, nclasses, nfeatures, save_path, save_fmaps=False, post_process_threshold=80, ROI=None)[source]¶ Quatify the learnt internal concepts by a network, only valid for segmentation networks
image : image (H x W x C) gt : image (H x W) threshold_maps : threshold maps used for dissection nclasses : number of classes nfeatures : number of feature maps to consider save_path : path to save csv with score for each featurs save_fmaps: saves images with fmap overlap post_process_threshold: threshold for postprocessing cc analysis ROI : region of interest mask in a given image
-