Process image and return disparity and feature maps.
(self, image: torch.Tensor)
| 192 | self.sorting_monodepth = sorting_monodepth |
| 193 | |
| 194 | def forward(self, image: torch.Tensor) -> MonodepthOutput: |
| 195 | """Process image and return disparity and feature maps.""" |
| 196 | inputs = self.monodepth_predictor.normalizer(image) |
| 197 | encoder_output = self.monodepth_predictor.encoder(inputs) |
| 198 | |
| 199 | num_encoder_features = len(self.monodepth_predictor.encoder.dims_encoder) |
| 200 | |
| 201 | # NOTE: whether intermediate features are empty have already been decided |
| 202 | # in monodepth_predictor during create_monodepth_dpt. |
| 203 | encoder_features = encoder_output[:num_encoder_features] |
| 204 | intermediate_features = encoder_output[num_encoder_features:] |
| 205 | decoder_features = self.monodepth_predictor.decoder(encoder_features) |
| 206 | disparity = self.monodepth_predictor.head(decoder_features) |
| 207 | |
| 208 | # We cannot use disparity.shape[1], otherwise the tracer will fail. |
| 209 | if self.num_monodepth_layers == 2 and self.sorting_monodepth: |
| 210 | first_layer_disparity = disparity.max(dim=1, keepdims=True).values |
| 211 | second_layer_disparity = disparity.min(dim=1, keepdims=True).values |
| 212 | disparity = torch.cat([first_layer_disparity, second_layer_disparity], dim=1) |
| 213 | |
| 214 | output_features = [] |
| 215 | if self.return_encoder_features: |
| 216 | output_features.extend(encoder_features) |
| 217 | |
| 218 | if self.return_decoder_features: |
| 219 | output_features.append(decoder_features) |
| 220 | |
| 221 | return MonodepthOutput( |
| 222 | disparity=disparity, |
| 223 | encoder_features=encoder_features, |
| 224 | decoder_features=decoder_features, |
| 225 | output_features=output_features, |
| 226 | intermediate_features=intermediate_features, |
| 227 | ) |
| 228 | |
| 229 | def get_feature_dims(self) -> list[int]: |
| 230 | """Return dimensions of output feature maps.""" |
nothing calls this directly
no test coverage detected