MCPcopy Create free account
hub / github.com/MotrixLab/ViMoGen / rendering_batches

Function rendering_batches

motion_rep/motion_checker.py:185–239  ·  view source on GitHub ↗

Render depth maps for all frames in batches.

(
    all_verts: torch.Tensor,
    faces: torch.Tensor,
    width: int,
    height: int,
    focal_length: float,
    R: Optional[torch.Tensor] = None,
    T: Optional[torch.Tensor] = None,
    batch_size: int = 8,
    render_multiple: bool = True,
    reverse_axis: bool = False,
)

Source from the content-addressed store, hash-verified

183
184
185def rendering_batches(
186 all_verts: torch.Tensor,
187 faces: torch.Tensor,
188 width: int,
189 height: int,
190 focal_length: float,
191 R: Optional[torch.Tensor] = None,
192 T: Optional[torch.Tensor] = None,
193 batch_size: int = 8,
194 render_multiple: bool = True,
195 reverse_axis: bool = False,
196) -> torch.Tensor:
197 """Render depth maps for all frames in batches."""
198 person_num = all_verts.shape[0]
199 frame_num = all_verts.shape[1]
200 verts_num = all_verts.shape[2]
201
202 if render_multiple:
203 multiple_person_faces = []
204 vert_offset = 0
205 for _ in range(person_num):
206 faces_offset = faces + vert_offset
207 multiple_person_faces.append(faces_offset)
208 vert_offset += verts_num
209 multiple_person_faces = torch.cat(multiple_person_faces, dim=0)
210
211 all_depth_maps = []
212 for i in range(0, frame_num, batch_size):
213 batch_start = i
214 batch_end = min(i + batch_size, frame_num)
215 batch_verts = all_verts[:, batch_start:batch_end].transpose(1, 0)
216 actual_batch_size = batch_end - batch_start
217 batch_R = R[batch_start:batch_end] if R is not None else None
218 batch_T = T[batch_start:batch_end] if T is not None else None
219
220 if render_multiple:
221 verts = batch_verts.reshape(actual_batch_size, person_num * verts_num, 3)
222 faces_tensor = multiple_person_faces.unsqueeze(0).repeat(actual_batch_size, 1, 1)
223 else:
224 verts = batch_verts
225 faces_tensor = faces.unsqueeze(0).repeat(actual_batch_size, 1, 1)
226
227 depth_maps = render_depth_maps(
228 vertices=verts,
229 faces=faces_tensor,
230 image_size=(height, width),
231 focal_length=focal_length,
232 reverse_axis=reverse_axis,
233 R=batch_R,
234 T=batch_T,
235 )
236 all_depth_maps.append(depth_maps)
237
238 depth_maps = torch.cat(all_depth_maps, dim=0)
239 return depth_maps
240
241
242def render_and_save_overlay(

Callers 2

render_and_save_overlayFunction · 0.85
render_and_saveFunction · 0.85

Calls 1

render_depth_mapsFunction · 0.85

Tested by

no test coverage detected