MCPcopy Create free account
hub / github.com/OpenDriveLab/ReSim / log_conditionings

Method log_conditionings

sat/diffusion_video.py:304–333  ·  view source on GitHub ↗

Defines heuristics to log different conditionings. These can be lists of strings (text-to-image), tensors, ints, ...

(self, batch: Dict, n: int)

Source from the content-addressed store, hash-verified

302
303 @torch.no_grad()
304 def log_conditionings(self, batch: Dict, n: int) -> Dict:
305 """
306 Defines heuristics to log different conditionings.
307 These can be lists of strings (text-to-image), tensors, ints, ...
308 """
309 image_h, image_w = batch[self.input_key].shape[3:]
310 log = dict()
311
312 for embedder in self.conditioner.embedders:
313 if ((self.log_keys is None) or (embedder.input_key in self.log_keys)) and not self.no_cond_log:
314 x = batch[embedder.input_key][:n]
315 if isinstance(x, torch.Tensor):
316 if x.dim() == 1:
317 x = [str(x[i].item()) for i in range(x.shape[0])]
318 xc = log_txt_as_img((image_h, image_w), x, size=image_h // 4)
319 elif x.dim() == 2:
320 # size and crop cond and the like
321 x = ["x".join([str(xx) for xx in x[i].tolist()]) for i in range(x.shape[0])]
322 xc = log_txt_as_img((image_h, image_w), x, size=image_h // 20)
323 else:
324 raise NotImplementedError()
325 elif isinstance(x, (List, ListConfig)):
326 if isinstance(x[0], str):
327 xc = log_txt_as_img((image_h, image_w), x, size=image_h // 20)
328 else:
329 raise NotImplementedError()
330 else:
331 raise NotImplementedError()
332 log[embedder.input_key] = xc
333 return log
334
335 @torch.no_grad()
336 def log_video(

Callers 1

log_videoMethod · 0.95

Calls 1

log_txt_as_imgFunction · 0.90

Tested by

no test coverage detected