(self, indices, shape)
| 116 | return z_q, loss, (perplexity, min_encodings, min_encoding_indices) |
| 117 | |
| 118 | def get_codebook_entry(self, indices, shape): |
| 119 | # shape specifying (batch, height, width, channel) |
| 120 | if self.remap is not None: |
| 121 | indices = indices.reshape(shape[0],-1) # add batch axis |
| 122 | indices = self.unmap_to_all(indices) |
| 123 | indices = indices.reshape(-1) # flatten again |
| 124 | |
| 125 | # get quantized latent vectors |
| 126 | z_q = self.embedding(indices) |
| 127 | |
| 128 | if shape is not None: |
| 129 | z_q = z_q.view(shape) |
| 130 | # reshape back to match original input shape |
| 131 | z_q = z_q.permute(0, 3, 1, 2).contiguous() |
| 132 | |
| 133 | return z_q |
| 134 | |
| 135 | class VQModel(pl.LightningModule): |
| 136 | def __init__(self, |
no test coverage detected