Convert a batch of img to code Args: model: The tokenizer model. img: [b, c, h, w]
(model, img)
| 213 | ) |
| 214 | |
| 215 | def img2code(model, img): |
| 216 | '''Convert a batch of img to code |
| 217 | Args: |
| 218 | model: The tokenizer model. |
| 219 | img: [b, c, h, w] |
| 220 | ''' |
| 221 | with torch.no_grad(): |
| 222 | quant_t1, _, id_t1 = model.encode(img) |
| 223 | return id_t1.view(img.shape[0], -1) |
| 224 | |
| 225 | def code2img(model, code): |
| 226 | '''Convert a batch of code to imgs |