Skip to content

Commit 60a22ff

Browse files
committed
Merge branch 'dev' into metatensor-merging
Signed-off-by: Wenqi Li <[email protected]>
2 parents d067aab + db02f07 commit 60a22ff

23 files changed

+1085
-89
lines changed

docs/source/apps.rst

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,16 @@ Applications
131131
.. automodule:: monai.apps.detection.utils.hard_negative_sampler
132132
:members:
133133

134-
`RetinaNet`
135-
~~~~~~~~~~~
134+
`RetinaNet Network`
135+
~~~~~~~~~~~~~~~~~~~
136136
.. automodule:: monai.apps.detection.networks.retinanet_network
137137
:members:
138138

139+
`RetinaNet Detector`
140+
~~~~~~~~~~~~~~~~~~~~
141+
.. automodule:: monai.apps.detection.networks.retinanet_detector
142+
:members:
143+
139144
`Transforms`
140145
~~~~~~~~~~~~
141146
.. automodule:: monai.apps.detection.transforms.box_ops

docs/source/losses.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ Segmentation Losses
5353
.. autoclass:: DiceFocalLoss
5454
:members:
5555

56+
`GeneralizedDiceFocalLoss`
57+
~~~~~~~~~~~~~~~~~~~~~~~~~~
58+
.. autoclass:: GeneralizedDiceFocalLoss
59+
:members:
60+
5661
`FocalLoss`
5762
~~~~~~~~~~~
5863
.. autoclass:: FocalLoss

docs/source/metrics.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ Metrics
3939
.. autoclass:: DiceMetric
4040
:members:
4141

42+
`Generalized Dice Score`
43+
------------------------
44+
.. autofunction:: compute_generalized_dice
45+
46+
.. autoclass:: GeneralizedDiceScore
47+
:members:
48+
4249
`Area under the ROC curve`
4350
--------------------------
4451
.. autofunction:: compute_roc_auc

monai/apps/detection/networks/retinanet_detector.py

Lines changed: 441 additions & 29 deletions
Large diffs are not rendered by default.

monai/apps/detection/networks/retinanet_network.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ class RetinaNet(nn.Module):
211211
num_anchors: number of anchors at each location.
212212
feature_extractor: a network that outputs feature maps from the input images,
213213
each feature map corresponds to a different resolution.
214-
Its output can have format of Tensor, Dict[Any, Tensor], or Sequence[Tensor].
214+
Its output can have a format of Tensor, Dict[Any, Tensor], or Sequence[Tensor].
215215
It can be the output of ``resnet_fpn_feature_extractor(*args, **kwargs)``.
216216
size_divisible: the spatial size of the network input should be divisible by size_divisible,
217217
decided by the feature_extractor.
@@ -242,7 +242,7 @@ class RetinaNet(nn.Module):
242242
trainable_backbone_layers = None,
243243
returned_layers = returned_layers,
244244
)
245-
# This feature_extractor requires input imgage spatial size
245+
# This feature_extractor requires input image spatial size
246246
# to be divisible by (32, 32, 16).
247247
size_divisible = tuple(2*s*2**max(returned_layers) for s in conv1_t_stride)
248248
model = RetinaNet(

monai/apps/detection/transforms/array.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,8 @@ def __call__( # type: ignore
328328

329329
class ClipBoxToImage(Transform):
330330
"""
331-
Clip the bounding boxes and the associated labels/scores to makes sure they are within the image.
332-
There might be multiple arryas of labels/scores associated with one array of boxes.
331+
Clip the bounding boxes and the associated labels/scores to make sure they are within the image.
332+
There might be multiple arrays of labels/scores associated with one array of boxes.
333333
334334
Args:
335335
remove_empty: whether to remove the boxes and corresponding labels that are actually empty

monai/apps/detection/utils/ATSS_matcher.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def __init__(
189189
self.center_in_gt = center_in_gt
190190
self.debug = debug
191191
logging.info(
192-
f"Running ATSS Matching with num_candidates={self.num_candidates} " f"and center_in_gt {self.center_in_gt}."
192+
f"Running ATSS Matching with num_candidates={self.num_candidates} and center_in_gt {self.center_in_gt}."
193193
)
194194

195195
def compute_matches(

monai/apps/detection/utils/anchor_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class AnchorGenerator(nn.Module):
7272
sizes: base size of each anchor.
7373
len(sizes) is the number of feature maps, i.e., the number of output levels for
7474
the feature pyramid network (FPN).
75-
Each elment of ``sizes`` is a Sequence which represents several anchor sizes for each feature map.
75+
Each element of ``sizes`` is a Sequence which represents several anchor sizes for each feature map.
7676
aspect_ratios: the aspect ratios of anchors. ``len(aspect_ratios) = len(sizes)``.
7777
For 2D images, each element of ``aspect_ratios[i]`` is a Sequence of float.
7878
For 3D images, each element of ``aspect_ratios[i]`` is a Sequence of 2 value Sequence.
@@ -286,7 +286,7 @@ def forward(self, images: Tensor, feature_maps: List[Tensor]) -> List[Tensor]:
286286
287287
Args:
288288
images: sized (B, C, W, H) or (B, C, W, H, D)
289-
feature_maps: for FPN level i, feature_maps[i] is sizec (B, C_i, W_i, H_i) or (B, C_i, W_i, H_i, D_i).
289+
feature_maps: for FPN level i, feature_maps[i] is sized (B, C_i, W_i, H_i) or (B, C_i, W_i, H_i, D_i).
290290
This input argument does not have to be the actual feature maps.
291291
Any list variable with the same (C_i, W_i, H_i) or (C_i, W_i, H_i, D_i) as feature maps works.
292292

monai/apps/detection/utils/detector_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def pad_images(
9797
) -> Tuple[Tensor, List[List[int]]]:
9898
"""
9999
Pad the input images, so that the output spatial sizes are divisible by `size_divisible`.
100-
It pad them at the end to create a (B, C, H, W) or (B, C, H, W, D) Tensor.
100+
It pads them at the end to create a (B, C, H, W) or (B, C, H, W, D) Tensor.
101101
Padded size (H, W) or (H, W, D) is divisible by size_divisible.
102102
Default padding uses constant padding with value 0.0
103103

monai/apps/detection/utils/hard_negative_sampler.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def select_negatives(self, negative: Tensor, num_neg: int, fg_probs: Tensor) ->
100100
class HardNegativeSampler(HardNegativeSamplerBase):
101101
"""
102102
HardNegativeSampler is used to suppress false positive rate in classification tasks.
103-
During training, it select negative samples with high prediction scores.
103+
During training, it selects negative samples with high prediction scores.
104104
105105
The training workflow is described as the follows:
106106
1) forward network and get prediction scores (classification prob/logits) for all the samples;
@@ -109,7 +109,7 @@ class HardNegativeSampler(HardNegativeSamplerBase):
109109
4) do back propagation.
110110
111111
Args:
112-
select_sample_size_per_image: number of training samples to be randomly selected per image
112+
batch_size_per_image: number of training samples to be randomly selected per image
113113
positive_fraction: percentage of positive elements in the selected samples
114114
min_neg: minimum number of negative samples to select if possible.
115115
pool_size: when we need ``num_neg`` hard negative samples, they will be randomly selected from
@@ -119,11 +119,11 @@ class HardNegativeSampler(HardNegativeSamplerBase):
119119
"""
120120

121121
def __init__(
122-
self, select_sample_size_per_image: int, positive_fraction: float, min_neg: int = 1, pool_size: float = 10
122+
self, batch_size_per_image: int, positive_fraction: float, min_neg: int = 1, pool_size: float = 10
123123
) -> None:
124124
super().__init__(pool_size=pool_size)
125125
self.min_neg = min_neg
126-
self.select_sample_size_per_image = select_sample_size_per_image
126+
self.batch_size_per_image = batch_size_per_image
127127
self.positive_fraction = positive_fraction
128128
logging.info("Sampling hard negatives on a per batch basis")
129129

@@ -148,7 +148,7 @@ def __call__(self, target_labels: List[Tensor], concat_fg_probs: Tensor) -> Tupl
148148
.. code-block:: python
149149
150150
sampler = HardNegativeSampler(
151-
select_sample_size_per_image=6, positive_fraction=0.5, min_neg=1, pool_size=2
151+
batch_size_per_image=6, positive_fraction=0.5, min_neg=1, pool_size=2
152152
)
153153
# two images with different number of samples
154154
target_labels = [ torch.tensor([0,1]), torch.tensor([1,0,2,1])]
@@ -183,7 +183,7 @@ def select_samples_img_list(
183183
.. code-block:: python
184184
185185
sampler = HardNegativeSampler(
186-
select_sample_size_per_image=6, positive_fraction=0.5, min_neg=1, pool_size=2
186+
batch_size_per_image=6, positive_fraction=0.5, min_neg=1, pool_size=2
187187
)
188188
# two images with different number of samples
189189
target_labels = [ torch.tensor([0,1]), torch.tensor([1,0,2,1])]
@@ -224,14 +224,14 @@ def select_samples_per_img(self, labels_per_img: Tensor, fg_probs_per_img: Tenso
224224
.. code-block:: python
225225
226226
sampler = HardNegativeSampler(
227-
select_sample_size_per_image=6, positive_fraction=0.5, min_neg=1, pool_size=2
227+
batch_size_per_image=6, positive_fraction=0.5, min_neg=1, pool_size=2
228228
)
229229
# two images with different number of samples
230230
target_labels = torch.tensor([1,0,2,1])
231231
fg_probs = torch.rand(4)
232232
pos_idx, neg_idx = sampler.select_samples_per_img(target_labels, fg_probs)
233233
"""
234-
# for each image, find positive sample incides and negative sample indices
234+
# for each image, find positive sample indices and negative sample indices
235235
if labels_per_img.numel() != fg_probs_per_img.numel():
236236
raise ValueError("labels_per_img and fg_probs_per_img should have same number of elements.")
237237

@@ -254,17 +254,17 @@ def get_num_pos(self, positive: torch.Tensor) -> int:
254254
positive: indices of positive samples
255255
256256
Returns:
257-
number of postive sample
257+
number of positive sample
258258
"""
259259
# positive sample sampling
260-
num_pos = int(self.select_sample_size_per_image * self.positive_fraction)
260+
num_pos = int(self.batch_size_per_image * self.positive_fraction)
261261
# protect against not enough positive examples
262262
num_pos = min(positive.numel(), num_pos)
263263
return num_pos
264264

265265
def get_num_neg(self, negative: torch.Tensor, num_pos: int) -> int:
266266
"""
267-
Sample enough negatives to fill up ``self.select_sample_size_per_image``
267+
Sample enough negatives to fill up ``self.batch_size_per_image``
268268
269269
Args:
270270
negative: indices of positive samples
@@ -292,7 +292,7 @@ def select_positives(self, positive: Tensor, num_pos: int, labels: Tensor) -> Te
292292
293293
Returns:
294294
binary mask of positive samples to choose, sized (A,),
295-
where A is the the number of samples in one image
295+
where A is the number of samples in one image
296296
"""
297297
if positive.numel() > labels.numel():
298298
raise ValueError("The number of positive samples should not be larger than the number of all samples.")

0 commit comments

Comments
 (0)