PEFT
Safetensors
omgwenxx commited on
Commit
b9ce6f4
·
verified ·
1 Parent(s): 7b6ae0e

Add model description and demo code

Browse files
Files changed (1) hide show
  1. README.md +21 -58
README.md CHANGED
@@ -5,73 +5,36 @@ library_name: peft
5
 
6
  # Model Card for Model ID
7
 
8
- <!-- Provide a quick summary of what the model is/does. -->
9
 
10
 
 
11
 
12
- ## Model Details
13
-
14
- ### Model Description
15
-
16
- <!-- Provide a longer summary of what this model is. -->
17
-
18
-
19
-
20
- - **Developed by:** [More Information Needed]
21
- - **Funded by [optional]:** [More Information Needed]
22
- - **Shared by [optional]:** [More Information Needed]
23
- - **Model type:** [More Information Needed]
24
- - **Language(s) (NLP):** [More Information Needed]
25
- - **License:** [More Information Needed]
26
- - **Finetuned from model [optional]:** [More Information Needed]
27
-
28
- ### Model Sources [optional]
29
-
30
- <!-- Provide the basic links for the model. -->
31
-
32
- - **Repository:** [More Information Needed]
33
- - **Paper [optional]:** [More Information Needed]
34
- - **Demo [optional]:** [More Information Needed]
35
-
36
- ## Uses
37
-
38
- <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
39
-
40
- ### Direct Use
41
-
42
- <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
43
-
44
- [More Information Needed]
45
-
46
- ### Downstream Use [optional]
47
-
48
- <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
49
-
50
- [More Information Needed]
51
-
52
- ### Out-of-Scope Use
53
-
54
- <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
55
-
56
- [More Information Needed]
57
-
58
- ## Bias, Risks, and Limitations
59
 
60
- <!-- This section is meant to convey both technical and sociotechnical limitations. -->
 
 
 
61
 
62
- [More Information Needed]
 
63
 
64
- ### Recommendations
 
65
 
66
- <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
 
67
 
68
- Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
 
69
 
70
- ## How to Get Started with the Model
71
-
72
- Use the code below to get started with the model.
73
-
74
- [More Information Needed]
 
75
 
76
  ## Training Details
77
 
 
5
 
6
  # Model Card for Model ID
7
 
8
+ This is an adapter for the Salesforce BLIP2 2.7B model (more information on the model [here](https://huggingface.co/Salesforce/blip2-opt-2.7b)). It was fine-tuned for generating product descriptions based on images using the [H&M dataset](https://www.kaggle.com/competitions/h-and-m-personalized-fashion-recommendations) from the kaggle challenge 2022.
9
 
10
 
11
+ ## How to Get Started with the Model
12
 
13
+ Use the code below to get started with the model. Make sure to replace the path with a local path to an image.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
 
15
+ ```python
16
+ from transformers import Blip2Processor, Blip2ForConditionalGeneration
17
+ from PIL import Image
18
+ import torch
19
 
20
+ torch_dtype = torch.bfloat16
21
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
22
 
23
+ base_checkpoint = "Salesforce/blip2-opt-2.7b"
24
+ base_model = Blip2ForConditionalGeneration.from_pretrained(base_checkpoint, torch_dtype=torch_dtype)
25
 
26
+ adapter_checkpoint = "CDL-RecSys/blip2-opt-2.7b-hm"
27
+ model = PeftModel.from_pretrained(base_model, model_id=adapter_checkpoint)
28
 
29
+ processor = Blip2Processor.from_pretrained(base_checkpoint)
30
+ tokenizer = processor.tokenizer
31
 
32
+ image = Image.open("path/to/your/image.jpg")
33
+ inputs = processor(image, return_tensors="pt").to(device, torch_dtype)
34
+ generated_ids = model.generate(**inputs, max_length=max_length)
35
+ generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)
36
+ generated_text
37
+ ```
38
 
39
  ## Training Details
40