Views
No views yet

$ pip install min-dalle1from min_dalle import MinDalle
2
3model = MinDalle(
4 models_root='./pretrained',
5 dtype=torch.float32,
6 device='cuda',
7 is_mega=True,
8 is_reusable=True
9)models_root if they are not already there. Set the dtype to torch.float16 to save GPU memory. If you have an Ampere architecture GPU you can use torch.bfloat16. Set the device to either "cuda" or "cpu". Once everything has finished initializing, call generate_image with some text as many times as you want. Use a positive seed for reproducible results. Higher values for supercondition_factor result in better agreement with the text but a narrower variety of generated images. Every image token is sampled from the top_k most probable tokens. The largest logit is subtracted from the logits to avoid infs. The logits are then divided by the temperature. If is_seamless is true, the image grid will be tiled in token space not pixel space.1image = model.generate_image(
2 text='Nuclear explosion broccoli',
3 seed=-1,
4 grid_size=4,
5 is_seamless=False,
6 temperature=1,
7 top_k=256,
8 supercondition_factor=32,
9 is_verbose=False
10)
11
12display(image)
FloatTensor in case you want to process them manually.1images = model.generate_images(
2 text='Nuclear explosion broccoli',
3 seed=-1,
4 grid_size=3,
5 is_seamless=False,
6 temperature=1,
7 top_k=256,
8 supercondition_factor=16,
9 is_verbose=False
10)images = images.to('cpu').numpy()1image = Image.fromarray(images[i])
2image.save('image_{}.png'.format(i))generate_image_stream can be used to generate a stream of images as the model is decoding. The detokenizer adds a slight delay for each image. Set progressive_outputs to True to enable this. An example is implemented in the colab.1image_stream = model.generate_image_stream(
2 text='Dali painting of WALL·E',
3 seed=-1,
4 grid_size=3,
5 progressive_outputs=True,
6 is_seamless=False,
7 temperature=1,
8 top_k=256,
9 supercondition_factor=16,
10 is_verbose=False
11)
12
13for image in image_stream:
14 display(image)
image_from_text.py to generate images from the command line.$ python image_from_text.py --text='artificial intelligence' --no-mega