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

Class RepeatChannel

monai/transforms/utility/array.py:237–259  ·  view source on GitHub ↗

Repeat channel data to construct expected input shape for models. The `repeats` count includes the origin data, for example: ``RepeatChannel(repeats=2)([[1, 2], [3, 4]])`` generates: ``[[1, 2], [1, 2], [3, 4], [3, 4]]`` Args: repeats: the number of repetitions for each elem

Source from the content-addressed store, hash-verified

235
236
237class RepeatChannel(Transform):
238 """
239 Repeat channel data to construct expected input shape for models.
240 The `repeats` count includes the origin data, for example:
241 ``RepeatChannel(repeats=2)([[1, 2], [3, 4]])`` generates: ``[[1, 2], [1, 2], [3, 4], [3, 4]]``
242
243 Args:
244 repeats: the number of repetitions for each element.
245 """
246
247 backend = [TransformBackends.TORCH]
248
249 def __init__(self, repeats: int) -> None:
250 if repeats <= 0:
251 raise ValueError(f"repeats count must be greater than 0, got {repeats}.")
252 self.repeats = repeats
253
254 def __call__(self, img: NdarrayOrTensor) -> NdarrayOrTensor:
255 """
256 Apply the transform to `img`, assuming `img` is a "channel-first" array.
257 """
258 repeat_fn = torch.repeat_interleave if isinstance(img, torch.Tensor) else np.repeat
259 return convert_to_tensor(repeat_fn(img, self.repeats, 0), track_meta=get_track_meta()) # type: ignore
260
261
262class RemoveRepeatedChannel(Transform):

Callers 2

__init__Method · 0.90
test_shapeMethod · 0.90

Calls

no outgoing calls

Tested by 1

test_shapeMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…