Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions ldm/util.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import importlib
import os

import torch
from torch import optim
Expand All @@ -16,7 +17,10 @@ def log_txt_as_img(wh, xc, size=10):
for bi in range(b):
txt = Image.new("RGB", wh, color="white")
draw = ImageDraw.Draw(txt)
font = ImageFont.truetype('font/DejaVuSans.ttf', size=size)
if os.path.isfile('font/DejaVuSans.ttf'):
font = ImageFont.truetype('font/DejaVuSans.ttf', size=size)
else:
font = ImageFont.load_default()
nc = int(40 * (wh[0] / 256))
lines = "\n".join(xc[bi][start:start + nc] for start in range(0, len(xc[bi]), nc))

Expand Down Expand Up @@ -194,4 +198,4 @@ def step(self, closure=None):
for param, ema_param in zip(params_with_grad, ema_params_with_grad):
ema_param.mul_(cur_ema_decay).add_(param.float(), alpha=1 - cur_ema_decay)

return loss
return loss