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

Method __call__

monai/apps/detection/transforms/array.py:365–397  ·  view source on GitHub ↗

Args: boxes: bounding boxes, Nx4 or Nx6 torch tensor or ndarray. The box mode is assumed to be ``StandardMode`` labels: Sequence of array. Each element represents classification labels or scores corresponding to ``boxes``, sized (N,). spat

(  # type: ignore
        self,
        boxes: NdarrayOrTensor,
        labels: Sequence[NdarrayOrTensor] | NdarrayOrTensor,
        spatial_size: Sequence[int] | int,
    )

Source from the content-addressed store, hash-verified

363 self.remove_empty = remove_empty
364
365 def __call__( # type: ignore
366 self,
367 boxes: NdarrayOrTensor,
368 labels: Sequence[NdarrayOrTensor] | NdarrayOrTensor,
369 spatial_size: Sequence[int] | int,
370 ) -> tuple[NdarrayOrTensor, tuple | NdarrayOrTensor]:
371 """
372 Args:
373 boxes: bounding boxes, Nx4 or Nx6 torch tensor or ndarray. The box mode is assumed to be ``StandardMode``
374 labels: Sequence of array. Each element represents classification labels or scores
375 corresponding to ``boxes``, sized (N,).
376 spatial_size: The spatial size of the image where the boxes are attached. len(spatial_size) should be in [2, 3].
377
378 Returns:
379 - clipped boxes, does not share memory with original boxes
380 - clipped labels, does not share memory with original labels
381
382 Example:
383 .. code-block:: python
384
385 box_clipper = ClipBoxToImage(remove_empty=True)
386 boxes = torch.ones(2, 6)
387 class_labels = torch.Tensor([0, 1])
388 pred_scores = torch.Tensor([[0.4,0.3,0.3], [0.5,0.1,0.4]])
389 labels = (class_labels, pred_scores)
390 spatial_size = [32, 32, 32]
391 boxes_clip, labels_clip_tuple = box_clipper(boxes, labels, spatial_size)
392 """
393 spatial_dims: int = get_spatial_dims(boxes=boxes)
394 spatial_size = ensure_tuple_rep(spatial_size, spatial_dims) # match the spatial image dim
395
396 boxes_clip, keep = clip_boxes_to_image(boxes, spatial_size, self.remove_empty)
397 return boxes_clip, select_labels(labels, keep)
398
399
400class BoxToMask(Transform):

Callers

nothing calls this directly

Calls 4

get_spatial_dimsFunction · 0.90
ensure_tuple_repFunction · 0.90
clip_boxes_to_imageFunction · 0.90
select_labelsFunction · 0.85

Tested by

no test coverage detected