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
| 235 | |
| 236 | |
| 237 | class 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 | |
| 262 | class RemoveRepeatedChannel(Transform): |
no outgoing calls
searching dependent graphs…