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

Method encode

sat/sgm/models/autoencoder.py:449–467  ·  view source on GitHub ↗
(self, x: torch.Tensor, return_reg_log: bool = False)

Source from the content-addressed store, hash-verified

447 return params
448
449 def encode(self, x: torch.Tensor, return_reg_log: bool = False) -> Union[torch.Tensor, Tuple[torch.Tensor, dict]]:
450 if self.max_batch_size is None:
451 z = self.encoder(x)
452 z = self.quant_conv(z)
453 else:
454 N = x.shape[0]
455 bs = self.max_batch_size
456 n_batches = int(math.ceil(N / bs))
457 z = list()
458 for i_batch in range(n_batches):
459 z_batch = self.encoder(x[i_batch * bs : (i_batch + 1) * bs])
460 z_batch = self.quant_conv(z_batch)
461 z.append(z_batch)
462 z = torch.cat(z, 0)
463
464 z, reg_log = self.regularization(z)
465 if return_reg_log:
466 return z, reg_log
467 return z
468
469 def decode(self, z: torch.Tensor, **decoder_kwargs) -> torch.Tensor:
470 if self.max_batch_size is None:

Callers

nothing calls this directly

Calls 1

appendMethod · 0.80

Tested by

no test coverage detected