MCPcopy Index your code
hub / github.com/zai-org/CogView / code2img

Function code2img

vqvae/api.py:32–44  ·  view source on GitHub ↗

Convert a batch of code to imgs Args: model: ... code: [b, h, w] or [b, h*w] LongTensor

(model, code)

Source from the content-addressed store, hash-verified

30 return id_t1.view(img.shape[0], -1)
31
32def code2img(model, code):
33 '''Convert a batch of code to imgs
34 Args:
35 model: ...
36 code: [b, h, w] or [b, h*w] LongTensor
37 '''
38 if len(code.shape) == 2:
39 s = int(math.sqrt(len(code.view(-1))) + 1e-5)
40 code = code.view(code.shape[0], s, s)
41 with torch.no_grad():
42 out = model.decode_code(code)
43 out = out * torch.tensor([0.30379, 0.32279, 0.32800], device=out.device).view(1, -1, 1, 1) + torch.tensor([0.79093, 0.76271, 0.75340], device=out.device).view(1, -1, 1, 1)
44 return out
45

Callers 2

DecodeIdsMethod · 0.90
show_recover_resultsFunction · 0.90

Calls 1

decode_codeMethod · 0.80

Tested by

no test coverage detected