From fff44d683e51e3ae0b6cd62d36cbfe025d7d69b4 Mon Sep 17 00:00:00 2001 From: Brett Kuprel Date: Fri, 1 Jul 2022 18:50:11 -0400 Subject: [PATCH] update readme, random seed if none specified --- README.md | 46 ++++++++++++++++-------------------- min_dalle/min_dalle_torch.py | 2 ++ 2 files changed, 22 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index a7f7149..72121af 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ The flax model, and the code for coverting it to torch, have been moved [here](h ### Install -```bash +```zsh $ pip install min-dalle ``` @@ -19,6 +19,16 @@ $ pip install min-dalle Use the python script `image_from_text.py` to generate images from the command line. +```zsh +$ python image_from_text.py --text='artificial intelligence' --seed=7 +``` +![Artificial Intelligence](examples/artificial_intelligence.png) + +```zsh +$ python image_from_text.py --text='court sketch of godzilla on trial' --mega +``` +![Godzilla Trial](examples/godzilla_on_trial.png) + To load a model once and generate multiple times, initialize `MinDalleTorch`, then call `generate_image` with some text and a seed. ```python @@ -29,33 +39,17 @@ model = MinDalleTorch( is_reusable=True, models_root='./pretrained' ) - -image = model.generate_image("court sketch of godzilla on trial", seed=40) ``` -Model parameters will be downloaded as needed to the directory specified. The models can also be manually downloaded [here](https://huggingface.co/kuprel/min-dalle/tree/main). - -### Examples - +```python +image = model.generate_image("a comfy chair that looks like an avocado") +display(image) ``` -python image_from_text.py --text='artificial intelligence' --seed=7 -``` -![Alien](examples/artificial_intelligence.png) +```python +image = model.generate_image("trail cam footage of gollum eating watermelon", seed=1) +display(image) +``` +![Gollum Trailcam](examples/gollum_trailcam.png) -``` -python image_from_text.py --text='a comfy chair that looks like an avocado' --mega --seed=10 -``` -![Avocado Armchair](examples/avocado_armchair.png) - - -``` -python image_from_text.py --text='court sketch of godzilla on trial' --mega --seed=40 -``` -![Godzilla Trial](examples/godzilla_on_trial.png) - - -``` -python image_from_text.py --text='trail cam footage of gollum eating watermelon' --mega --seed=1 -``` -![Gollum Trailcam](examples/gollum_trailcam.png) \ No newline at end of file +Model parameters will be downloaded as needed to the directory specified. The models can also be manually downloaded [here](https://huggingface.co/kuprel/min-dalle/tree/main). \ No newline at end of file diff --git a/min_dalle/min_dalle_torch.py b/min_dalle/min_dalle_torch.py index 2950f0a..212f461 100644 --- a/min_dalle/min_dalle_torch.py +++ b/min_dalle/min_dalle_torch.py @@ -6,6 +6,7 @@ from torch import LongTensor import torch import json import requests +import random torch.set_grad_enabled(False) torch.set_num_threads(os.cpu_count()) @@ -167,6 +168,7 @@ class MinDalleTorch: if not self.is_reusable: self.init_decoder() print("sampling image tokens") + if seed < 0: seed = random.randint(0, 2 ** 31) torch.manual_seed(seed) image_tokens = self.decoder.forward(text_tokens, encoder_state) if not self.is_reusable: del self.decoder