update readme, random seed if none specified
This commit is contained in:
parent
ec9e22e4d4
commit
fff44d683e
44
README.md
vendored
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
|
### Install
|
||||||
|
|
||||||
```bash
|
```zsh
|
||||||
$ pip install min-dalle
|
$ 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.
|
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.
|
To load a model once and generate multiple times, initialize `MinDalleTorch`, then call `generate_image` with some text and a seed.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
|
@ -29,33 +39,17 @@ model = MinDalleTorch(
|
||||||
is_reusable=True,
|
is_reusable=True,
|
||||||
models_root='./pretrained'
|
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).
|
```python
|
||||||
|
image = model.generate_image("a comfy chair that looks like an avocado")
|
||||||
### Examples
|
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)
|
||||||
python image_from_text.py --text='a comfy chair that looks like an avocado' --mega --seed=10
|
display(image)
|
||||||
```
|
|
||||||
![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)
|
![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 torch
|
||||||
import json
|
import json
|
||||||
import requests
|
import requests
|
||||||
|
import random
|
||||||
torch.set_grad_enabled(False)
|
torch.set_grad_enabled(False)
|
||||||
torch.set_num_threads(os.cpu_count())
|
torch.set_num_threads(os.cpu_count())
|
||||||
|
|
||||||
|
@ -167,6 +168,7 @@ class MinDalleTorch:
|
||||||
|
|
||||||
if not self.is_reusable: self.init_decoder()
|
if not self.is_reusable: self.init_decoder()
|
||||||
print("sampling image tokens")
|
print("sampling image tokens")
|
||||||
|
if seed < 0: seed = random.randint(0, 2 ** 31)
|
||||||
torch.manual_seed(seed)
|
torch.manual_seed(seed)
|
||||||
image_tokens = self.decoder.forward(text_tokens, encoder_state)
|
image_tokens = self.decoder.forward(text_tokens, encoder_state)
|
||||||
if not self.is_reusable: del self.decoder
|
if not self.is_reusable: del self.decoder
|
||||||
|
|
Loading…
Reference in New Issue
Block a user