MCPcopy Create free account
hub / github.com/Ropedia/SpatialBench / forward

Method forward

benchmark/models/zipmap/zipmap/models/ZipMap.py:108–188  ·  view source on GitHub ↗

Forward pass of the VGGT model. Args: images (torch.Tensor): Input images with shape [S, 3, H, W] or [B, S, 3, H, W], in range [0, 1]. B: batch size, S: sequence length, 3: RGB channels, H: height, W: width query_info (torch.Tensor, optional)

(self, images: torch.Tensor, query_info: torch.Tensor = None, store_state: bool = False)

Source from the content-addressed store, hash-verified

106
107
108 def forward(self, images: torch.Tensor, query_info: torch.Tensor = None, store_state: bool = False):
109 """
110 Forward pass of the VGGT model.
111
112 Args:
113 images (torch.Tensor): Input images with shape [S, 3, H, W] or [B, S, 3, H, W], in range [0, 1].
114 B: batch size, S: sequence length, 3: RGB channels, H: height, W: width
115 query_info (torch.Tensor, optional): Query information for NVS,
116 Default: None
117
118 """
119 # If without batch dimension, add it
120 if len(images.shape) == 4:
121 images = images.unsqueeze(0)
122
123 if query_info is not None and self.nvs_head is not None:
124 aggregator_query_conditions = self.get_aggregator_query_conditions(query_info)
125 else:
126 aggregator_query_conditions = None
127
128 info = {
129 # "ttt_op_order": ttt_op_order, # define later in forward
130 "store_state": store_state, # if to store the state_list for future queries
131 }
132
133 aggregated_tokens_list, patch_start_idx, state_list = self.aggregator(images, target_query_conditions=aggregator_query_conditions, info=info)
134
135 input_view_num = images.shape[1]
136 input_img_aggregated_tokens_list = [tokens[:, :input_view_num, :] for tokens in aggregated_tokens_list]
137
138 predictions = {}
139 with torch.amp.autocast(device_type='cuda', enabled=False):
140 if self.camera_head is not None:
141 pose_enc_list = self.camera_head(input_img_aggregated_tokens_list)
142 predictions["pose_enc"] = pose_enc_list[-1] # pose encoding of the last iteration
143 predictions["pose_enc_list"] = pose_enc_list # var type: a list of predictions["pose_enc"] of each iteration
144
145
146 if self.camera_svd_head is not None:
147 pose_enc_svd_list = self.camera_svd_head(input_img_aggregated_tokens_list)
148 predictions["pose_enc_svd"] = pose_enc_svd_list[-1] # pose encoding of the last iteration
149 predictions["pose_enc_svd_list"] = pose_enc_svd_list # var type: a list of predictions["pose_enc"] of each iteration
150
151 if self.depth_head is not None:
152 depth, depth_conf = self.depth_head(
153 input_img_aggregated_tokens_list, images=images, patch_start_idx=patch_start_idx
154 )
155 predictions["depth"] = depth
156 predictions["depth_conf"] = depth_conf
157
158 if self.local_point_head is not None:
159 pts3d, pts3d_conf = self.local_point_head(
160 input_img_aggregated_tokens_list, images=images, patch_start_idx=patch_start_idx
161 )
162 predictions["local_points"] = pts3d
163 predictions["local_points_conf"] = pts3d_conf
164
165

Callers

nothing calls this directly

Calls 1

Tested by

no test coverage detected