Skip to content

Commit b2664e8

Browse files
committed
fix debug_image to not crash with non-RGB images.
1 parent 8753120 commit b2664e8

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

ldm/util.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
import importlib
2-
3-
import torch
4-
import numpy as np
52
import math
6-
from collections import abc
7-
from einops import rearrange
8-
from functools import partial
9-
103
import multiprocessing as mp
11-
from threading import Thread
4+
from collections import abc
5+
from inspect import isfunction
126
from queue import Queue
7+
from threading import Thread
138

14-
from inspect import isfunction
9+
import numpy as np
10+
import torch
1511
from PIL import Image, ImageDraw, ImageFont
1612

1713

@@ -221,7 +217,7 @@ def rand_perlin_2d(shape, res, device, fade = lambda t: 6*t**5 - 15*t**4 + 10*t*
221217
grid = torch.stack(torch.meshgrid(torch.arange(0, res[0], delta[0]), torch.arange(0, res[1], delta[1]), indexing='ij'), dim = -1).to(device) % 1
222218

223219
rand_val = torch.rand(res[0]+1, res[1]+1)
224-
220+
225221
angles = 2*math.pi*rand_val
226222
gradients = torch.stack((torch.cos(angles), torch.sin(angles)), dim = -1).to(device)
227223

@@ -249,8 +245,8 @@ def ask_user(question: str, answers: list):
249245
def debug_image(debug_image, debug_text, debug_show=True, debug_result=False, debug_status=False ):
250246
if not debug_status:
251247
return
252-
253-
image_copy = debug_image.copy()
248+
249+
image_copy = debug_image.copy().convert("RGBA")
254250
ImageDraw.Draw(image_copy).text(
255251
(5, 5),
256252
debug_text,
@@ -261,4 +257,4 @@ def debug_image(debug_image, debug_text, debug_show=True, debug_result=False, de
261257
image_copy.show()
262258

263259
if debug_result:
264-
return image_copy
260+
return image_copy

0 commit comments

Comments
 (0)