MCPcopy Create free account
hub / github.com/VisionXLab/OF-Diff / log_txt_as_img

Function log_txt_as_img

ldm/util.py:11–32  ·  view source on GitHub ↗
(wh, xc, size=10)

Source from the content-addressed store, hash-verified

9
10
11def log_txt_as_img(wh, xc, size=10):
12 # wh a tuple of (width, height)
13 # xc a list of captions to plot
14 b = len(xc)
15 txts = list()
16 for bi in range(b):
17 txt = Image.new("RGB", wh, color="white")
18 draw = ImageDraw.Draw(txt)
19 font = ImageFont.truetype('font/DejaVuSans.ttf', size=size)
20 nc = int(40 * (wh[0] / 256))
21 lines = "\n".join(xc[bi][start:start + nc] for start in range(0, len(xc[bi]), nc))
22
23 try:
24 draw.text((0, 0), lines, fill="black", font=font)
25 except UnicodeEncodeError:
26 print("Cant encode string for logging. Skipping.")
27
28 txt = np.array(txt).transpose(2, 0, 1) / 127.5 - 1.0
29 txts.append(txt)
30 txts = np.stack(txts)
31 txts = torch.tensor(txts)
32 return txts
33
34
35def ismap(x):

Callers 4

log_imagesMethod · 0.90
log_imagesMethod · 0.90
log_imagesMethod · 0.90
log_imagesMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected