(wh, xc, size=10)
| 9 | |
| 10 | |
| 11 | def 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 | |
| 35 | def ismap(x): |
no outgoing calls
no test coverage detected