Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to use example #167

Closed
nonetrix opened this issue Aug 7, 2022 · 2 comments
Closed

Unable to use example #167

nonetrix opened this issue Aug 7, 2022 · 2 comments

Comments

@nonetrix
Copy link

nonetrix commented Aug 7, 2022

Most likely user error but using the examples provided doesn't work

pip install imagen-pytorch
import torch
from imagen_pytorch import Unet, Imagen

# unet for imagen

unet1 = Unet(
    dim = 32,
    cond_dim = 512,
    dim_mults = (1, 2, 4, 8),
    num_resnet_blocks = 3,
    layer_attns = (False, True, True, True),
    layer_cross_attns = (False, True, True, True)
)

unet2 = Unet(
    dim = 32,
    cond_dim = 512,
    dim_mults = (1, 2, 4, 8),
    num_resnet_blocks = (2, 4, 8, 8),
    layer_attns = (False, False, False, True),
    layer_cross_attns = (False, False, False, True)
)

# imagen, which contains the unets above (base unet and super resoluting ones)

imagen = Imagen(
    unets = (unet1, unet2),
    image_sizes = (64, 256),
    timesteps = 1000,
    cond_drop_prob = 0.1
).cuda()

# mock images (get a lot of this) and text encodings from large T5

text_embeds = torch.randn(4, 256, 768).cuda()
images = torch.randn(4, 3, 256, 256).cuda()

# feed images into imagen, training each unet in the cascade

for i in (1, 2):
    loss = imagen(images, text_embeds = text_embeds, unet_number = i)
    loss.backward()

# do the above for many many many many steps
# now you can sample an image based on the text embeddings from the cascading ddpm

images = imagen.sample(texts = [
    'a whale breaching from afar',
    'young girl blowing out candles on her birthday cake',
    'fireworks with blue and green sparkles'
], cond_scale = 3.)

images.shape # (3, 3, 256, 256)
The base dimension of your u-net should ideally be no smaller than 128, as recommended by a professional DDPM trainer https://nonint.com/2022/05/04/friends-dont-let-friends-train-small-diffusion-models/
Traceback (most recent call last):
  File "test.py", line 26, in <module>
    imagen = Imagen(
  File "/home/user/.local/lib/python3.8/site-packages/imagen_pytorch/imagen_pytorch.py", line 1821, in __init__
    assert not (exists(video_frames) and video_frames < 1), 'video frames must be at least 1 or greater'
NameError: name 'video_frames' is not defined

Trying to define the missing variable does nothing or returns the blow error depending where I put it

The base dimension of your u-net should ideally be no smaller than 128, as recommended by a professional DDPM trainer https://nonint.com/2022/05/04/friends-dont-let-friends-train-small-diffusion-models/
Traceback (most recent call last):
  File "test.py", line 28, in <module>
    imagen = Imagen(
TypeError: __init__() got an unexpected keyword argument 'video_frames'

I am not trying to generate videos so I have no idea why it is asking for this in the first place

@lucidrains
Copy link
Owner

Oops, trying to fix this on phone

Try 1.6.4?

@debagos
Copy link

debagos commented Aug 7, 2022

Thank you for the quick response, problem solved 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants