singi73737373 commited on
Commit
60cf22d
·
verified ·
1 Parent(s): 34706e0

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +52 -52
README.md CHANGED
@@ -1,87 +1,87 @@
1
  ---
2
- library_name: transformers
3
- license: apache-2.0
4
- language:
5
  - en
6
  base_model:
7
  - Qwen/Qwen2-VL-7B-Instruct
8
- pipeline_tag: image-to-text
9
  ---
10
 
11
- # Qwen2-VL-7B-Captioner-Relaxed
12
 
13
- ## Introduction
14
 
15
- Qwen2-VL-7B-Captioner-Relaxed is an instruction-tuned version of [Qwen2-VL-7B-Instruct](https://huggingface.co/Qwen/Qwen2-VL-7B-Instruct), an advanced multimodal large language model. This fine-tuned version is based on a hand-curated dataset for text-to-image models, providing significantly more detailed descriptions of given images.
16
 
17
- ### Key Features:
18
 
19
- * **Enhanced Detail:** Generates more comprehensive and nuanced image descriptions.
20
- * **Relaxed Constraints:** Offers less restrictive image descriptions compared to the base model.
21
- * **Natural Language Output:** Describes different subjects in the image while specifying their locations using natural language.
22
- * **Optimized for Image Generation:** Produces captions in formats compatible with state-of-the-art text-to-image generation models.
23
 
24
- **Note:** This fine-tuned model is optimized for creating text-to-image datasets. As a result, performance on other tasks (e.g., ~10% decrease on mmmu_val) may be lower compared to the original model.
25
 
26
- ## Requirements
27
 
28
- If you encounter errors such as `KeyError: 'qwen2_vl'` or `ImportError: cannot import name 'Qwen2VLForConditionalGeneration' from 'transformers'`, try installing the latest version of the transformers library from source:
29
 
30
- `pip install git+https://github.com/huggingface/transformers`
31
 
32
- ## Quickstart
33
- ```python
34
- from PIL import Image
35
- from transformers import Qwen2VLForConditionalGeneration, AutoProcessor
36
- from transformers import BitsAndBytesConfig
37
- import torch
38
 
39
- model_id = "Ertugrul/Qwen2-VL-7B-Captioner-Relaxed"
40
 
41
- model = Qwen2VLForConditionalGeneration.from_pretrained(
42
- model_id, torch_dtype=torch.bfloat16, device_map="auto"
43
  )
44
- processor = AutoProcessor.from_pretrained(model_id)
45
 
46
- conversation = [
47
  {
48
- "role": "user",
49
- "content": [
50
  {
51
- "type": "image",
52
- },
53
- {"type": "text", "text": "Describe this image."},
54
- ],
55
  }
56
  ]
57
 
58
 
59
 
60
- image = Image.open(r"PATH_TO_YOUR_IMAGE")
61
 
62
- # you can resize the image here if it's not fitting to vram, or set model max sizes.
63
- # image = image.resize((1024, 1024)) # like this
64
 
65
- text_prompt = processor.apply_chat_template(conversation, add_generation_prompt=True)
66
 
67
- inputs = processor(
68
- text=[text_prompt], images=[image], padding=True, return_tensors="pt"
69
  )
70
- inputs = inputs.to("cuda")
71
 
72
- with torch.no_grad():
73
- with torch.autocast(device_type="cuda", dtype=torch.bfloat16):
74
- output_ids = model.generate(**inputs, max_new_tokens=384, do_sample=True, temperature=0.7, use_cache=True, top_k=50)
75
 
76
 
77
- generated_ids = [
78
- output_ids[len(input_ids) :]
79
- for input_ids, output_ids in zip(inputs.input_ids, output_ids)
80
  ]
81
- output_text = processor.batch_decode(
82
- generated_ids, skip_special_tokens=True, clean_up_tokenization_spaces=True
83
- )[0]
84
- print(output_text)
85
- ```
86
 
87
- For more detailed options, refer to the [Qwen2-VL-7B-Instruct](https://huggingface.co/Qwen/Qwen2-VL-7B-Instruct) documentation.
 
1
  ---
2
+ Bibliothek_name: Transformatoren
3
+ Lizenz: Apache-2.0
4
+ Kratze:
5
  - en
6
  base_model:
7
  - Qwen/Qwen2-VL-7B-Instruct
8
+ pipeline_tag: Bild-zu-text
9
  ---
10
 
11
+ # Qwen2-VL-7 B-Captioner-Entspannt
12
 
13
+ ## Einleitung
14
 
15
+ Qwen2-VL-7 B-Captioner-Entspannte ist eine weisungsgestimmte Version von [Qwen2-VL-7B-Instruct](https://huggingface.co/Qwen/Qwen2-VL-7B-Instruct), ein fortschrittliches multimodales Großsprachenmodell. Diese fein abgestimmte Version basiert auf einem handkuratieren Datensatz für Text-zu-Bild-Modelle und bietet deutlich detailliert Beschreibungen gebebener Bilder.
16
 
17
+ ### Hauptmerkmale:
18
 
19
+ * **Erweitertes Detail:** Produkte umfassendere und differenzierte Bildbeschreibungen.
20
+ * **Entspanntes Einschränkungen:** Bietet im Verein zum Basismodell weniger restriktive Bildbeschreibungen.
21
+ * **Ausgabe naturlicher Sprache:** Beschreibt verschiedene Motive im Bild und gibt gleichzeit ihre Standorte in naturlicher Sprache an.
22
+ * **Optimiert für die Bilderzeugung:** Produzierte Bildunterschriften in Formaten, die mit modernsten Text-zu-Bild-Generierungsmodelle kompatibel sind.
23
 
24
+ **Anmerkung:** Dieses fin abgestimmte Modell ist für die Erstellung von Text-zu-Bild-Datensätzen optimiert. Infolgedessen kann die Lehrung bei anderen Aufgeben (z. B. ~10% Abnahme bei mmmu_val) im Verein zum Originalmodell geringer sein.
25
 
26
+ ## Anfordungen
27
 
28
+ Wenn Sie auf Fehler stoßen wie `KeyError: 'qwen2_vl'` Oder `ImportError: kann Name 'Qwen2VLForConditionalGeneration' nicht aus 'Transformers' importieren`, Versuchen Sie, die neueste Version der Transformatorenbibliothek aus der Quelle zu installieren:
29
 
30
+ `pip installieren git+https://github.com/huggingface/transformers`
31
 
32
+ ## Schnellstart
33
+ `Python
34
+ Von PIL-Import Bild
35
+ Von Transformatoren importieren Qwen2VLForConditionalGeneration, AutoProcessor
36
+ Von Transformatoren BitsAndBytesConfig importieren
37
+ Einfuhrbrenner
38
 
39
+ model_id = "Ertugrul/Qwen2-VL-7 B-Captioner-Relaxed"
40
 
41
+ Modell = Qwen2VLForConditionalGeneration.from_pretrained (
42
+ model_id, torch_dtyp=torch.bfloat16, device_map="auto"
43
  )
44
+ Prozessor = AutoProcessor.from_pretrained (model_id)
45
 
46
+ Gesprüch = [
47
  {
48
+ "Rolle": "Benutzer",
49
+ "inhalt": [
50
  {
51
+ "type": "Bild",
52
+ },
53
+ {"type": "text", "text": "Beschreibe dieses Bild"},
54
+ ],
55
  }
56
  ]
57
 
58
 
59
 
60
+ Bild = Image.open (r "PATH_TO_YOUR_IMAGE")
61
 
62
+ # Sie können die Größe des Bildes hier Ändern, wenn es nicht zu vram passt, oder Modellmaximalgrößen festlegen.
63
+ # Bild = Bild.resize ((1024, 1024)) # so
64
 
65
+ text_prompt = processor.apply_chat_template (Gespräch, add_generation_prompt=True)
66
 
67
+ Eingänge = Prozessor (
68
+ text=[text_prompt], images=[Bild], udding=True, return_tensors="pt"
69
  )
70
+ Eingänge = Eingänge.to ("cuda")
71
 
72
+ mit Fackel.no_grad ():
73
+ mit torch.autocast (device_type=" cuda", dtype=torch.bfloat16):
74
+ output_ids = model.generate (**inputs, max_new_tokens=384, do_sample=True, temperatur=0.7, use_cache=True, top_k=50)
75
 
76
 
77
+ generierte_ids = [
78
+ Ausgabe_ids[len (input_ids):]
79
+ Für input_ids, output_ids in zip (inputs.input_ids, output_ids)
80
  ]
81
+ Ausgabe_text = processor.batch_decode (
82
+ generated_ids, skip_special_tokens=True, clean_up_tokenization_spaces=True
83
+ [0]
84
+ Ausdrucken (output_text)
85
+ `
86
 
87
+ Ausführliche Optionen finden Sie in der [Qwen2-VL-7B-Instruct] (https://huggingface.co/Qwen/Qwen2-VL-7B-Instruct) Dokumentation.