dblasko commited on
Commit
a9d5518
1 Parent(s): ef19e3f

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +31 -1
README.md CHANGED
@@ -11,4 +11,34 @@ tags:
11
 
12
  # DALL·E 3 Image prompt reverse-engineering
13
 
14
- Pre-trained image-captioning model BLIP fine-tuned on a mixture of `laion/dalle-3-dataset` and semi-automatically gathered `(image, prompt)` data from DALLE·E 3. It takes a generated image as an input and outputs a potential prompt to generate such an image, which can then be used as a base to generate similar images.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
  # DALL·E 3 Image prompt reverse-engineering
13
 
14
+ Pre-trained image-captioning model BLIP fine-tuned on a mixture of `laion/dalle-3-dataset` and semi-automatically gathered `(image, prompt)` data from DALLE·E 3.
15
+
16
+ It takes a generated image as an input and outputs a potential prompt to generate such an image, which can then be used as a base to generate similar images.
17
+
18
+ ### Usage:
19
+
20
+ Loading the model and preprocessor:
21
+ ```python
22
+ from transformers import BlipForConditionalGeneration, AutoProcessor
23
+
24
+ model = BlipForConditionalGeneration.from_pretrained("blip-dalle3-img2prompt").to(device)
25
+ processor = AutoProcessor.from_pretrained("blip-dalle3-img2prompt")
26
+ ```
27
+
28
+ Inference example on an image from `laion/dalle-3-dataset`:
29
+ ```python
30
+ from datasets import load_dataset
31
+
32
+ dataset = load_dataset("laion/dalle-3-dataset", split=f'train[0%:1%]') # for fast download time in the toy example
33
+ example = dataset[img_index][0]
34
+ image = example["image"]
35
+ caption = example["caption"]
36
+
37
+ inputs = processor(images=image, return_tensors="pt").to(device)
38
+ pixel_values = inputs.pixel_values
39
+
40
+ generated_ids = model.generate(pixel_values=pixel_values, max_length=50)
41
+ generated_caption = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
42
+
43
+ print(f"Generated caption: {generated_caption}\nReal caption: {caption}")
44
+ ```