| 128 | |
| 129 | |
| 130 | def _copy_compatible_dict(from_dict: dict, to_dict: dict): |
| 131 | if not isinstance(to_dict, dict): |
| 132 | raise ValueError(f"to_dict must be a Dict, got {type(to_dict)}.") |
| 133 | if not to_dict: |
| 134 | for key in from_dict: |
| 135 | datum = from_dict[key] |
| 136 | if isinstance(datum, np.ndarray) and np_str_obj_array_pattern.search(datum.dtype.str) is not None: |
| 137 | continue |
| 138 | to_dict[key] = str(TraceKeys.NONE) if datum is None else datum # NoneType to string for default_collate |
| 139 | else: |
| 140 | affine_key, shape_key = MetaKeys.AFFINE, MetaKeys.SPATIAL_SHAPE |
| 141 | if affine_key in from_dict and not np.allclose(from_dict[affine_key], to_dict[affine_key]): |
| 142 | raise RuntimeError( |
| 143 | "affine matrix of all images should be the same for channel-wise concatenation. " |
| 144 | f"Got {from_dict[affine_key]} and {to_dict[affine_key]}." |
| 145 | ) |
| 146 | if shape_key in from_dict and not np.allclose(from_dict[shape_key], to_dict[shape_key]): |
| 147 | raise RuntimeError( |
| 148 | "spatial_shape of all images should be the same for channel-wise concatenation. " |
| 149 | f"Got {from_dict[shape_key]} and {to_dict[shape_key]}." |
| 150 | ) |
| 151 | |
| 152 | |
| 153 | def _stack_images(image_list: list, meta_dict: dict, to_cupy: bool = False): |