MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / randomize

Method randomize

monai/transforms/croppad/array.py:1321–1343  ·  view source on GitHub ↗
(
        self,
        label: torch.Tensor | None = None,
        indices: list[NdarrayOrTensor] | None = None,
        image: torch.Tensor | None = None,
    )

Source from the content-addressed store, hash-verified

1319 self.max_samples_per_class = max_samples_per_class
1320
1321 def randomize(
1322 self,
1323 label: torch.Tensor | None = None,
1324 indices: list[NdarrayOrTensor] | None = None,
1325 image: torch.Tensor | None = None,
1326 ) -> None:
1327 indices_ = self.indices if indices is None else indices
1328 if indices_ is None:
1329 if label is None:
1330 raise ValueError("label must not be None.")
1331 indices_ = map_classes_to_indices(
1332 label, self.num_classes, image, self.image_threshold, self.max_samples_per_class
1333 )
1334 _shape = None
1335 if label is not None:
1336 _shape = label.peek_pending_shape() if isinstance(label, MetaTensor) else label.shape[1:]
1337 elif image is not None:
1338 _shape = image.peek_pending_shape() if isinstance(image, MetaTensor) else image.shape[1:]
1339 if _shape is None:
1340 raise ValueError("label or image must be provided to infer the output spatial shape.")
1341 self.centers = generate_label_classes_crop_centers(
1342 self.spatial_size, self.num_samples, _shape, indices_, self.ratios, self.R, self.allow_smaller, self.warn
1343 )
1344
1345 @LazyTransform.lazy.setter # type: ignore
1346 def lazy(self, _val: bool):

Callers 1

__call__Method · 0.95

Calls 3

map_classes_to_indicesFunction · 0.90
peek_pending_shapeMethod · 0.80

Tested by

no test coverage detected