uf-aice-lab commited on
Commit
f42f2a2
·
verified ·
1 Parent(s): 433c465

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +34 -1
README.md CHANGED
@@ -1,4 +1,37 @@
1
  ---
2
  license: mit
3
  ---
4
- dddddddddddddddddddd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: mit
3
  ---
4
+
5
+ This is the structure of the BLIPNet model. You can load the model with it, or you can create a bigger model for your task.
6
+
7
+ class BLIPNet(torch.nn.Module):
8
+ def __init__(self, ):
9
+ super().__init__()
10
+ #Generation Model
11
+ self.model = BlipForConditionalGeneration.from_pretrained(MODEL_NAME, cache_dir="model")
12
+ #Same with https://huggingface.co/uf-aice-lab/BLIP-Math
13
+ self.ebd_dim = ebd_dim= 443136
14
+
15
+ #Classification Model
16
+ fc_dim = 64 # You can choose a higher number for better performance, for example, 1024.
17
+ self.head = nn.Sequential(
18
+ nn.Linear(self.ebd_dim, fc_dim),
19
+ nn.ReLU(),
20
+ )
21
+ self.score = nn.Linear(fc_dim, 5) #5 classes
22
+
23
+
24
+ def forward(self, pixel_values, input_ids):
25
+ outputs = self.model(input_ids=input_ids, pixel_values=pixel_values, labels=input_ids)
26
+ image_text_embeds = self.model.vision_model(pixel_values, return_dict=True).last_hidden_state
27
+ image_text_embeds = self.head(image_embeds.view(-1, self.ebd_dim))
28
+
29
+ #A classification model is based on embeddings from a generative model to leverage BLIP's powerful image-text encoding capabilities.
30
+ logits = self.score(image_embeds)
31
+
32
+ #generated text, probabilities of classification
33
+ return outputs, logits
34
+
35
+ You need to input the sample in the same way as:
36
+ https://huggingface.co/uf-aice-lab/BLIP-Math
37
+ Then you can get the text and score at the same time.