Prepare sample for usage as network input.
| 160 | |
| 161 | |
| 162 | class PrepareForNet(object): |
| 163 | """Prepare sample for usage as network input. |
| 164 | """ |
| 165 | def __init__(self): |
| 166 | pass |
| 167 | |
| 168 | def __call__(self, sample): |
| 169 | image = np.transpose(sample["image"], (2, 0, 1)) |
| 170 | sample["image"] = np.ascontiguousarray(image).astype(np.float32) |
| 171 | |
| 172 | if "mask" in sample: |
| 173 | sample["mask"] = sample["mask"].astype(np.float32) |
| 174 | sample["mask"] = np.ascontiguousarray(sample["mask"]) |
| 175 | |
| 176 | if "disparity" in sample: |
| 177 | disparity = sample["disparity"].astype(np.float32) |
| 178 | sample["disparity"] = np.ascontiguousarray(disparity) |
| 179 | |
| 180 | if "depth" in sample: |
| 181 | depth = sample["depth"].astype(np.float32) |
| 182 | sample["depth"] = np.ascontiguousarray(depth) |
| 183 | |
| 184 | return sample |