mapreader.process.occlusion_analysis

Classes

OcclusionAnalyzer

A class for carrying out occlusion analysis on patches.

Module Contents

class mapreader.process.occlusion_analysis.OcclusionAnalyzer(patch_df, model, transform='default', delimiter=',', device='default')

A class for carrying out occlusion analysis on patches.

Parameters:
  • patch_df (pd.DataFrame | gpd.GeoDataFrame | str | pathlib.Path) – The DataFrame containing patches and predictions.

  • model (str or nn.Module) – The PyTorch model to add to the object. If a string, this should be the path to a model checkpoint.

  • transform (str or callable) – The transform to apply to the patches. Options of “default” or a torchvision transform. Default transform

  • delimiter (str) – The delimiter used in the patch_df csv file. By default, “,”.

  • device (str) – The device to use. By default, “default”.

loss_fn = None
add_loss_fn(loss_fn='cross entropy')

Add a loss function to the object.

Parameters:

loss_fn (str or torch.nn.modules.loss._Loss) – The loss function to use. Can be a string or a torch.nn loss function. Accepted string values are “cross entropy” or “ce” (cross-entropy), “bce” (binary cross-entropy) and “mse” (mean squared error). By default, “cross entropy” is used.

Return type:

None

run_occlusion(label, sample_size=10, save=False, path_save='./occlusion_analysis/', block_size=14)

Run occlusion analysis on a sample of patches for a given label.

Parameters:
  • label (str) – The label to run the analysis on.

  • sample_size (int) – The number of patches to run the analysis on. By default, 10.

  • save (bool) – Whether to save the occlusion analysis images. By default, False.

  • path_save (str) – The path to save the occlusion analysis images to. By default, “./occlusion_analysis/”.

  • block_size (int) – The size of the occlusion block. By default, 14.