Vittorio Pippi
commited on
Commit
·
eca827c
1
Parent(s):
605e556
Update README with PyTorch import and example adjustments for batch image generation
Browse files
README.md
CHANGED
|
@@ -56,6 +56,7 @@ library_name: t5
|
|
| 56 |
Below is a minimal usage example in Python. You can load the model with `AutoModel.from_pretrained(...)` and simply call `.generate(...)` or `.generate_batch(...)` to create images.
|
| 57 |
|
| 58 |
```python
|
|
|
|
| 59 |
from PIL import Image
|
| 60 |
from transformers import AutoModel
|
| 61 |
from huggingface_hub import hf_hub_download
|
|
@@ -67,7 +68,7 @@ def load_image(img_path):
|
|
| 67 |
img = img.resize((img.width * 64 // img.height, 64))
|
| 68 |
img = F.to_tensor(img)
|
| 69 |
img = F.normalize(img, [0.5], [0.5])
|
| 70 |
-
return img
|
| 71 |
|
| 72 |
# 1. Load the model
|
| 73 |
model = AutoModel.from_pretrained("blowing-up-groundhogs/emuru", trust_remote_code=True)
|
|
@@ -96,10 +97,10 @@ generated_pil_image.save("generated_image.png")
|
|
| 96 |
You can also generate a batch of images if you have multiple style texts, generation texts, and style images:
|
| 97 |
|
| 98 |
```python
|
| 99 |
-
style_texts = [
|
| 100 |
-
gen_texts = [
|
| 101 |
-
style_imgs = torch.stack([
|
| 102 |
-
lengths = [
|
| 103 |
|
| 104 |
output_images = model.generate_batch(
|
| 105 |
style_texts=style_texts,
|
|
@@ -120,6 +121,6 @@ for idx, pil_img in enumerate(output_images):
|
|
| 120 |
If you use Emuru in your research or wish to refer to it, please cite:
|
| 121 |
|
| 122 |
```
|
| 123 |
-
...
|
| 124 |
```
|
| 125 |
|
|
|
|
| 56 |
Below is a minimal usage example in Python. You can load the model with `AutoModel.from_pretrained(...)` and simply call `.generate(...)` or `.generate_batch(...)` to create images.
|
| 57 |
|
| 58 |
```python
|
| 59 |
+
import torch
|
| 60 |
from PIL import Image
|
| 61 |
from transformers import AutoModel
|
| 62 |
from huggingface_hub import hf_hub_download
|
|
|
|
| 68 |
img = img.resize((img.width * 64 // img.height, 64))
|
| 69 |
img = F.to_tensor(img)
|
| 70 |
img = F.normalize(img, [0.5], [0.5])
|
| 71 |
+
return img
|
| 72 |
|
| 73 |
# 1. Load the model
|
| 74 |
model = AutoModel.from_pretrained("blowing-up-groundhogs/emuru", trust_remote_code=True)
|
|
|
|
| 97 |
You can also generate a batch of images if you have multiple style texts, generation texts, and style images:
|
| 98 |
|
| 99 |
```python
|
| 100 |
+
style_texts = ['THE JOLLY IS "U"', 'THE JOLLY IS "M"', 'THE JOLLY IS "R"']
|
| 101 |
+
gen_texts = ['EMURU', 'EMURU', 'EMURU']
|
| 102 |
+
style_imgs = torch.stack([style_img, style_img, style_img], dim=0) # shape: (batch_size, C, H, W)
|
| 103 |
+
lengths = [style_img.size(-1), style_img.size(-1), style_img.size(-1)]
|
| 104 |
|
| 105 |
output_images = model.generate_batch(
|
| 106 |
style_texts=style_texts,
|
|
|
|
| 121 |
If you use Emuru in your research or wish to refer to it, please cite:
|
| 122 |
|
| 123 |
```
|
| 124 |
+
Wait for it...
|
| 125 |
```
|
| 126 |
|