TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/ragavsachdeva/CYWS-3D/llms.txt
Use this file to discover all available pages before exploring further.
Model class is the central PyTorch module of CYWS-3D. It accepts a prepared batch dict, computes paired CenterNet outputs for both images in a scene pair, and decodes them into bounding boxes that mark changed regions. The model is configured entirely through an EasyDict loaded from config.yml and optionally initialised from a .ckpt checkpoint file. All public methods follow standard nn.Module conventions.
Constructor
Configuration object produced by
get_easy_dict_from_yaml_file("config.yml"). Controls model architecture choices such as backbone, CenterNet head dimensions, and registration module settings. The structure mirrors the top-level keys in config.yml.Path to a
.ckpt checkpoint file. When supplied, the constructor calls safely_load_state_dict to restore weights. When None, the model starts with random initialisation — only useful for training from scratch.Model.predict(batch)
torch.no_grad() and decodes the raw CenterNet logits into bounding boxes via get_bboxes_from_logits. This is the recommended entry point for inference.
Returns a tuple of two lists, each of length batch_size:
| Return value | Type | Description |
|---|---|---|
batch_image1_predicted_bboxes | List[Tuple[Tensor, Tensor]] | Per-image-1 detections for every batch item |
batch_image2_predicted_bboxes | List[Tuple[Tensor, Tensor]] | Per-image-2 detections for every batch item |
(bboxes_tensor, labels_tensor) tuple where:
bboxes_tensor— shape[N, 5], dtypefloat. The last dimension is[x1, y1, x2, y2, score]in 224×224 pixel coordinates.labels_tensor— shape[N], dtypelong. Class labels for each detection (single-class models always emit0).
predict is decorated with @torch.no_grad() — you do not need to wrap the call in a with torch.no_grad() block yourself.utils.py before visualisation:
Model.forward(batch)
| Return value | Type | Description |
|---|---|---|
image1_centernet_outputs | Tuple[Tensor, Tensor, Tensor] | (heatmap, wh, offset) for image 1 |
image2_centernet_outputs | Tuple[Tensor, Tensor, Tensor] | (heatmap, wh, offset) for image 2 |
heatmap— class probability map, shape[B, C, H', W']wh— bounding box width/height predictions, shape[B, 2, H', W']offset— sub-pixel offset correction, shape[B, 2, H', W']
Model.compute_loss(batch, image1_outputs, image2_outputs)
Tensor. The loss terms for image 1 and image 2 are summed.
The batch dict must contain the following training-only keys in addition to the standard inference keys:
| Key | Type | Description |
|---|---|---|
target_bbox_1 | Tensor | Ground-truth bounding boxes for image 1 |
target_bbox_labels1 | Tensor | Class labels for each ground-truth box in image 1 |
target_bbox_2 | Tensor | Ground-truth bounding boxes for image 2 |
target_bbox_labels2 | Tensor | Class labels for each ground-truth box in image 2 |
query_metadata | dict | CenterNet head metadata (stride, output size); added by prepare_batch_for_model |
Model.safely_load_state_dict(checkpoint_state_dict)
load_state_dict. Instead of raising an error on shape mismatches, it:
- Skips any parameter whose checkpoint shape differs from the current model shape, keeping the randomly initialised value.
- Drops checkpoint keys that do not exist in the current model (e.g. keys left over from a previous architecture version).
Batch Format
Model.forward and Model.predict expect a batch dictionary with the following keys. The batch is assembled by create_batch_from_metadata and finalised by prepare_batch_for_model.
| Key | Shape / Type | Description |
|---|---|---|
image1 | Tensor [B, C, 224, 224] | ImageNet-normalised RGB image 1, stacked across the batch |
image2 | Tensor [B, C, 224, 224] | ImageNet-normalised RGB image 2, stacked across the batch |
depth1 | per-item Tensor | Metric or relative depth map for image 1; predicted by ZoeDepth if absent in metadata |
depth2 | per-item Tensor | Metric or relative depth map for image 2 |
intrinsics1 | per-item ndarray (3,3) | Camera intrinsics matrix for image 1; adjusted for 224×224 resize |
intrinsics2 | per-item ndarray (3,3) | Camera intrinsics matrix for image 2 |
position1 | per-item ndarray (3,) | World-space translation of camera 1 |
position2 | per-item ndarray (3,) | World-space translation of camera 2 |
rotation1 | per-item ndarray (3,3) | Rotation matrix for camera 1 |
rotation2 | per-item ndarray (3,3) | Rotation matrix for camera 2 |
transfm2d_1_to_2 | per-item ndarray (3,3) | 2-D homography from image 1 to image 2 |
transfm2d_2_to_1 | per-item ndarray (3,3) | 2-D homography from image 2 to image 1 |
registration_strategy | List[str] | One entry per batch item: "3d", "2d", "2d_from_corr", or "identity" |
query_metadata | dict | CenterNet stride and output resolution metadata; added by prepare_batch_for_model |
points1 | per-item Tensor | Normalised [0,1] keypoint coordinates in image 1; added by CorrespondenceExtractor |
points2 | per-item Tensor | Normalised [0,1] keypoint coordinates in image 2; added by CorrespondenceExtractor |
Keys related to camera geometry (
intrinsics, position, rotation, transfm2d_*) are only required when the corresponding registration_strategy needs them. The model reads registration_strategy per item and routes accordingly.