update readme, random seed if none specified

main
Brett Kuprel 2 years ago
parent ec9e22e4d4
commit fff44d683e
  1. 44
      README.md
  2. 2
      min_dalle/min_dalle_torch.py

44
README.md vendored

@ -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_from_text.py --text='artificial intelligence' --seed=7
```
![Alien](examples/artificial_intelligence.png)
```
python image_from_text.py --text='a comfy chair that looks like an avocado' --mega --seed=10
```python
image = model.generate_image("a comfy chair that looks like an avocado")
display(image)
```
![Avocado Armchair](examples/avocado_armchair.png)
```
python image_from_text.py --text='court sketch of godzilla on trial' --mega --seed=40
```python
image = model.generate_image("trail cam footage of gollum eating watermelon", seed=1)
display(image)
```
![Godzilla Trial](examples/godzilla_on_trial.png)
![Gollum Trailcam](examples/gollum_trailcam.png)
```
python image_from_text.py --text='trail cam footage of gollum eating watermelon' --mega --seed=1
```
![Gollum Trailcam](examples/gollum_trailcam.png)
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).

@ -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

Loading…
Cancel
Save