-2

I've been playing around with stable diffusion on Google colab, and I've been having some trouble getting a grid to work. Every time I run my image generator block, it gets through the generation but can't display the images, it gives me the error stated in the title.

def image_grid(imgs, rows, cols):

    assert len(imgs) == rows*cols
    w, h = imgs[0].size
    grid = Image.new('RGB', size=(cols*w, rows*h))
    grid_w, grid_h = grid.size

    for i, img in enumerate(imgs):
        grid.paste(img, box=(i%cols*w, i//cols*h))

    return grid

This runs fine, but this next part is what screws me over.

from torch import autocast
num_images = 4
prompt = ["Astronaut riding a horse"] * num_images
with autocast("cuda"):
  images = pipe(prompt, width=512, height=512, num_inference_steps=10)["sample"]
grid = image_grid(images, rows=2, cols=2)
grid
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-30-ec9ce225f081> in <module>
     16   images = pipe(prompt, width=512, height=512, num_inference_steps=10)["sample"]
     17 
---> 18 grid = image_grid(images, rows=2, cols=2)
     19 grid

<ipython-input-28-2e81f9e2985a> in image_grid(imgs, rows, cols)
     10     for i, img in enumerate(imgs):
     11         grid.paste(img, box=(i%cols*w, i//cols*h))
---> 12     return grid()

TypeError: 'Image' object is not callable
CD912
  • 1
  • 2

1 Answers1

0

First, removed [0], then changed 'return grid()' to 'return grid' Thanks, OneCricketeer.

CD912
  • 1
  • 2
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 04 '22 at 12:22