fastMONAI 0.3.1__py3-none-any.whl → 0.3.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,50 +11,67 @@ from monai.metrics import compute_hausdorff_distance, compute_dice
11
11
  from .vision_data import pred_to_binary_mask, batch_pred_to_multiclass_mask
12
12
 
13
13
  # %% ../nbs/05_vision_metrics.ipynb 3
14
- def calculate_dsc(pred, targ):
15
- ''' MONAI `compute_meandice`'''
14
+ def calculate_dsc(pred: torch.Tensor, targ: torch.Tensor) -> torch.Tensor:
15
+ """MONAI `compute_meandice`"""
16
16
 
17
17
  return torch.Tensor([compute_dice(p[None], t[None]) for p, t in list(zip(pred,targ))])
18
18
 
19
19
  # %% ../nbs/05_vision_metrics.ipynb 4
20
- def calculate_haus(pred, targ):
21
- ''' MONAI `compute_hausdorff_distance`'''
20
+ def calculate_haus(pred: torch.Tensor, targ: torch.Tensor) -> torch.Tensor:
21
+ """MONAI `compute_hausdorff_distance`"""
22
22
 
23
23
  return torch.Tensor([compute_hausdorff_distance(p[None], t[None]) for p, t in list(zip(pred,targ))])
24
24
 
25
25
  # %% ../nbs/05_vision_metrics.ipynb 5
26
- def binary_dice_score(act, # Activation tensor [B, C, W, H, D]
27
- targ # Target masks [B, C, W, H, D]
28
- ) -> torch.Tensor:
29
- '''Calculate the mean Dice score for binary semantic segmentation tasks.'''
30
-
26
+ def binary_dice_score(act: torch.tensor, targ: torch.Tensor) -> torch.Tensor:
27
+ """Calculates the mean Dice score for binary semantic segmentation tasks.
28
+
29
+ Args:
30
+ act: Activation tensor with dimensions [B, C, W, H, D].
31
+ targ: Target masks with dimensions [B, C, W, H, D].
32
+
33
+ Returns:
34
+ Mean Dice score.
35
+ """
31
36
  pred = pred_to_binary_mask(act)
32
37
  dsc = calculate_dsc(pred.cpu(), targ.cpu())
33
38
 
34
39
  return torch.mean(dsc)
35
40
 
36
41
  # %% ../nbs/05_vision_metrics.ipynb 6
37
- def multi_dice_score(act, # Activation values [B, C, W, H, D]
38
- targ # Target masks [B, C, W, H, D]
39
- ) -> torch.Tensor:
40
- '''Calculate the mean Dice score for each class in multi-class semantic segmentation tasks.'''
42
+ def multi_dice_score(act: torch.Tensor, targ: torch.Tensor) -> torch.Tensor:
43
+ """Calculate the mean Dice score for each class in multi-class semantic
44
+ segmentation tasks.
41
45
 
46
+ Args:
47
+ act: Activation tensor with dimensions [B, C, W, H, D].
48
+ targ: Target masks with dimensions [B, C, W, H, D].
42
49
 
50
+ Returns:
51
+ Mean Dice score for each class.
52
+ """
43
53
  pred, n_classes = batch_pred_to_multiclass_mask(act)
44
54
  binary_dice_scores = []
45
55
 
46
56
  for c in range(1, n_classes):
47
- c_pred, c_targ = torch.where(pred==c, 1, 0), torch.where(targ==c, 1, 0)
57
+ c_pred, c_targ = torch.where(pred == c, 1, 0), torch.where(targ == c, 1, 0)
48
58
  dsc = calculate_dsc(c_pred, c_targ)
49
- binary_dice_scores.append(np.nanmean(dsc)) #TODO update torch to get torch.nanmean() to work
59
+ binary_dice_scores.append(np.nanmean(dsc)) # #TODO update torch to get torch.nanmean() to work
50
60
 
51
61
  return torch.Tensor(binary_dice_scores)
52
62
 
53
63
  # %% ../nbs/05_vision_metrics.ipynb 7
54
- def binary_hausdorff_distance(act, # Activation tensor [B, C, W, H, D]
55
- targ # Target masks [B, C, W, H, D]
56
- ) -> torch.Tensor:
57
- '''Calculate the mean Hausdorff distance for binary semantic segmentation tasks.'''
64
+ def binary_hausdorff_distance(act: torch.Tensor, targ: torch.Tensor) -> torch.Tensor:
65
+ """Calculate the mean Hausdorff distance for binary semantic segmentation tasks.
66
+
67
+ Args:
68
+ act: Activation tensor with dimensions [B, C, W, H, D].
69
+ targ: Target masks with dimensions [B, C, W, H, D].
70
+
71
+ Returns:
72
+ Mean Hausdorff distance.
73
+ """
74
+
58
75
 
59
76
  pred = pred_to_binary_mask(act)
60
77
 
@@ -62,10 +79,16 @@ def binary_hausdorff_distance(act, # Activation tensor [B, C, W, H, D]
62
79
  return torch.mean(haus)
63
80
 
64
81
  # %% ../nbs/05_vision_metrics.ipynb 8
65
- def multi_hausdorff_distance(act, # Activation tensor [B, C, W, H, D]
66
- targ # Target masks [B, C, W, H, D]
67
- ) -> torch.Tensor :
68
- '''Calculate the mean Hausdorff distance for each class in multi-class semantic segmentation tasks.'''
82
+ def multi_hausdorff_distance(act: torch.Tensor, targ: torch.Tensor) -> torch.Tensor :
83
+ """Calculate the mean Hausdorff distance for each class in multi-class semantic segmentation tasks.
84
+
85
+ Args:
86
+ act: Activation tensor with dimensions [B, C, W, H, D].
87
+ targ: Target masks with dimensions [B, C, W, H, D].
88
+
89
+ Returns:
90
+ Mean Hausdorff distance for each class.
91
+ """
69
92
 
70
93
  pred, n_classes = batch_pred_to_multiclass_mask(act)
71
94
  binary_haus = []
fastMONAI/vision_plot.py CHANGED
@@ -9,8 +9,7 @@ from torchio.visualization import rotate
9
9
 
10
10
  # %% ../nbs/00_vision_plot.ipynb 3
11
11
  def _get_slice(image, channel: int, indices: (int, list), anatomical_plane: int, voxel_size: (int, list)):
12
- """
13
- A private method to get a 2D tensor and aspect ratio for plotting.
12
+ """A private method to get a 2D tensor and aspect ratio for plotting.
14
13
  This is modified code from the torchio function `plot_volume`.
15
14
 
16
15
  Args:
@@ -53,11 +52,9 @@ def _get_slice(image, channel: int, indices: (int, list), anatomical_plane: int,
53
52
 
54
53
  # %% ../nbs/00_vision_plot.ipynb 4
55
54
  @delegates(plt.Axes.imshow, keep=True, but=['shape', 'imlim'])
56
- def show_med_img(
57
- im, ctx, channel: int, indices: (int, list), anatomical_plane: int,
58
- voxel_size: (int, list), ax=None, figsize=None, title=None, **kwargs):
59
- """
60
- Show an image on `ax`. This is a modified code from the fastai function `show_image`.
55
+ def show_med_img(im, ctx, channel: int, indices: (int, list), anatomical_plane: int,
56
+ voxel_size: (int, list), ax=None, figsize=None, title=None, **kwargs):
57
+ """Show an image on `ax`. This is a modified code from the fastai function `show_image`.
61
58
 
62
59
  Args:
63
60
  im: The input image.
@@ -74,18 +71,23 @@ def show_med_img(
74
71
  Returns:
75
72
  Axis with the plot.
76
73
  """
77
- if hasattrs(im, ('data', 'cpu', 'permute')):
74
+ if hasattrs(im, ('data', 'cpu', 'permute')): # Check if `im` has the necessary attributes
78
75
  im = im.data.cpu()
79
76
  im, aspect = _get_slice(
80
- im, channel=channel, anatomical_plane=anatomical_plane,
81
- voxel_size=voxel_size, indices=indices
77
+ im,
78
+ channel=channel,
79
+ anatomical_plane=anatomical_plane,
80
+ voxel_size=voxel_size,
81
+ indices=indices
82
82
  )
83
83
 
84
- ax = ifnone(ax, ctx)
85
- if ax is None:
86
- _, ax = plt.subplots(figsize=figsize) # ax is only None when .show() is used.
84
+ ax = ax if ax is not None else ctx
85
+
86
+ if ax is None: # ax is only None when .show() is used.
87
+ _, ax = plt.subplots(figsize=figsize)
87
88
 
88
89
  ax.imshow(im, aspect=aspect, **kwargs)
90
+
89
91
  if title is not None:
90
92
  ax.set_title(title)
91
93
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: fastMONAI
3
- Version: 0.3.1
3
+ Version: 0.3.3
4
4
  Summary: fastMONAI library
5
5
  Home-page: https://github.com/MMIV-ML/fastMONAI
6
6
  Author: Satheshkumar Kaliyugarasan
@@ -0,0 +1,20 @@
1
+ fastMONAI/__init__.py,sha256=8KcCYTXH99C2-gCLuPILJvtT9YftRWJsartIx6TQ2ZY,22
2
+ fastMONAI/_modidx.py,sha256=AGOW75o_d2Vd7CBku-4zz53OzUqkp4QqTEqsucyU7jg,27510
3
+ fastMONAI/dataset_info.py,sha256=w5LKGmEzFtlqhxqzhFLWUfyVkUL0EYypZQCH9Ay6jgg,4948
4
+ fastMONAI/external_data.py,sha256=Hq4GPEWsBi9-fyk9r3WlBdUZjfNzeaKe5uqTwFD8qfU,11016
5
+ fastMONAI/research_utils.py,sha256=LZu62g8BQAVYS4dD7qDsKHJXZnDd1uLkJ6LoaMDhUhk,590
6
+ fastMONAI/utils.py,sha256=9I5nl6Sb0NbTxhr6FDnW4dapDhzPtmxGcJeXkkY4v3E,1406
7
+ fastMONAI/vision_all.py,sha256=qAsncBCDTx3Ae8Hw44TK4E5wflO-8JbRWBu0CRLLGnY,360
8
+ fastMONAI/vision_augmentation.py,sha256=lAlrLm8jbXRmk9a6e8_o_CNTS6Pyp-KKNXwjpelUUJc,9070
9
+ fastMONAI/vision_core.py,sha256=KDoLS9UYNsh5nPIYc2JiDjWBLy1IRSpjH9cqEHjk4Vw,7428
10
+ fastMONAI/vision_data.py,sha256=QZqHK35L9sU9BiQ2nIqGzOEBAGHfuke7YloyZrPkYto,10491
11
+ fastMONAI/vision_inference.py,sha256=k-rGKhVtdrZT9GvQEglEa0sZ283ue16mEPTZ-ZSKc5Q,3744
12
+ fastMONAI/vision_loss.py,sha256=NrHnk1yD4EBKsp6aippppXU4l-mwmsZOqE_bsZP3ZNI,3591
13
+ fastMONAI/vision_metrics.py,sha256=CVxdOBPaMJT6Mo5jF3WoQj6a3C-_FsnBicMAU_ZrFS8,3549
14
+ fastMONAI/vision_plot.py,sha256=S2_yE0VcAwECgvXHb1YMJbTZq4iREh-VIgPShLcUma0,3095
15
+ fastMONAI-0.3.3.dist-info/LICENSE,sha256=xV8xoN4VOL0uw9X8RSs2IMuD_Ss_a9yAbtGNeBWZwnw,11337
16
+ fastMONAI-0.3.3.dist-info/METADATA,sha256=xVkZtZdie9sgwLhpKNl8yZaA7YKFDDFLYB-PDo5yOeA,5770
17
+ fastMONAI-0.3.3.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
18
+ fastMONAI-0.3.3.dist-info/entry_points.txt,sha256=mVBsykSXMairzzk3hJaQ8c-UiwUZqGnn4aFZ24CpsBM,40
19
+ fastMONAI-0.3.3.dist-info/top_level.txt,sha256=o8y7SWF9odtnIT3jvYtUn9okbJRlaAMCy7oPFCeQvQ8,10
20
+ fastMONAI-0.3.3.dist-info/RECORD,,
@@ -1,20 +0,0 @@
1
- fastMONAI/__init__.py,sha256=r4xAFihOf72W9TD-lpMi6ntWSTKTP2SlzKP1ytkjRbI,22
2
- fastMONAI/_modidx.py,sha256=Tp9TjFPpgC4R8zVx0avHRoGX-H-aGKJukuvUhvu-FwU,29361
3
- fastMONAI/dataset_info.py,sha256=ZCqha0HcuhGcRxCG5TAsGua0gam3C2ZnyjjpG47gcHo,4795
4
- fastMONAI/external_data.py,sha256=_HU5mTJs5xSS8y0be51mrfQ93HJUidq6PGm9n6rfOW4,8357
5
- fastMONAI/research_utils.py,sha256=LZu62g8BQAVYS4dD7qDsKHJXZnDd1uLkJ6LoaMDhUhk,590
6
- fastMONAI/utils.py,sha256=oPEfBEJDlUzNu5KTuwFW5bjuieI7SqdOlbcy7eiTazA,1431
7
- fastMONAI/vision_all.py,sha256=qAsncBCDTx3Ae8Hw44TK4E5wflO-8JbRWBu0CRLLGnY,360
8
- fastMONAI/vision_augmentation.py,sha256=9O7pafQz9PP_bqA0drjeVVg6_uqKUT-L-lGtW2k7fjw,9887
9
- fastMONAI/vision_core.py,sha256=dLsl3IRkssQ-iXljwcsixP3hU0IzLfhvHhyKNUtMFCk,6553
10
- fastMONAI/vision_data.py,sha256=99BL-yrXoXHNjWYbtI49t0E1lEXiY5FFHy_TSgXBjEI,9193
11
- fastMONAI/vision_inference.py,sha256=Q5Dd-kCK639QF7qkgnbniQPcCM0oHvYt5xEn07YuIxU,3352
12
- fastMONAI/vision_loss.py,sha256=_Rf8rpsNb2cru8R3NGU1WNxuR0pWN7acX6qjNT-lPcE,3674
13
- fastMONAI/vision_metrics.py,sha256=mY3Nw6hN7qh-zrpT-kXjJj6J3bd5DFAfmpxVMVHFdfU,3035
14
- fastMONAI/vision_plot.py,sha256=vot916053eK8xTVnK2fOGJ6mfruzKZsS-Qae3-4m5Vw,2997
15
- fastMONAI-0.3.1.dist-info/LICENSE,sha256=xV8xoN4VOL0uw9X8RSs2IMuD_Ss_a9yAbtGNeBWZwnw,11337
16
- fastMONAI-0.3.1.dist-info/METADATA,sha256=1pdeHnOQBY2z9uaCrVoNxU-6TsMCYAadovuF6m-Z5Ao,5770
17
- fastMONAI-0.3.1.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
18
- fastMONAI-0.3.1.dist-info/entry_points.txt,sha256=mVBsykSXMairzzk3hJaQ8c-UiwUZqGnn4aFZ24CpsBM,40
19
- fastMONAI-0.3.1.dist-info/top_level.txt,sha256=o8y7SWF9odtnIT3jvYtUn9okbJRlaAMCy7oPFCeQvQ8,10
20
- fastMONAI-0.3.1.dist-info/RECORD,,