rjiang12 commited on
Commit
c2c8861
1 Parent(s): e0f3c8c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -9
app.py CHANGED
@@ -25,10 +25,10 @@ vilt_model = ViltForQuestionAnswering.from_pretrained("dandelin/vilt-b32-finetun
25
  device = "cuda" if torch.cuda.is_available() else "cpu"
26
 
27
  git_model_base.to(device)
28
- blip_model_base.to(device)
29
  #git_model_large.to(device)
30
  #blip_model_large.to(device)
31
- vilt_model.to(device)
32
 
33
  def generate_answer_git(processor, model, image, question):
34
  # prepare image
@@ -42,10 +42,16 @@ def generate_answer_git(processor, model, image, question):
42
  generated_ids = model.generate(pixel_values=pixel_values, input_ids=input_ids, max_length=50, return_dict_in_generate=True, output_scores=True)
43
  print('scores:')
44
  print(generated_ids.scores)
45
- scoresList0 = torch.softmax(generated_ids.scores[0], dim=1).flatten().tolist()
46
- print(scoresList0)
47
- scoresList1 = torch.softmax(generated_ids.scores[1], dim=1).flatten().tolist()
48
- print(scoresList1)
 
 
 
 
 
 
49
  print('sequences:')
50
  print(generated_ids.sequences)
51
  print(generated_ids)
@@ -82,13 +88,13 @@ def generate_answers(image, question):
82
 
83
  # answer_git_large = generate_answer_git(git_processor_large, git_model_large, image, question)
84
 
85
- answer_blip_base = generate_answer_blip(blip_processor_base, blip_model_base, image, question)
86
 
87
  # answer_blip_large = generate_answer_blip(blip_processor_large, blip_model_large, image, question)
88
 
89
- answer_vilt = generate_answer_vilt(vilt_processor, vilt_model, image, question)
90
 
91
- return answer_git_base, answer_blip_base, answer_vilt
92
 
93
 
94
  examples = [["cats.jpg", "How many cats are there?"], ["stop_sign.png", "What's behind the stop sign?"], ["astronaut.jpg", "What's the astronaut riding on?"]]
 
25
  device = "cuda" if torch.cuda.is_available() else "cpu"
26
 
27
  git_model_base.to(device)
28
+ # blip_model_base.to(device)
29
  #git_model_large.to(device)
30
  #blip_model_large.to(device)
31
+ # vilt_model.to(device)
32
 
33
  def generate_answer_git(processor, model, image, question):
34
  # prepare image
 
42
  generated_ids = model.generate(pixel_values=pixel_values, input_ids=input_ids, max_length=50, return_dict_in_generate=True, output_scores=True)
43
  print('scores:')
44
  print(generated_ids.scores)
45
+ # scoresList0 = torch.softmax(generated_ids.scores[0], dim=1).flatten().tolist()
46
+ # print(scoresList0)
47
+ # scoresList1 = torch.softmax(generated_ids.scores[1], dim=1).flatten().tolist()
48
+ # print(scoresList1)
49
+ idx = generated_ids.scores[0].argmax(-1).item()
50
+ idx1 = generated_ids.scores[1].argmax(-1).item()
51
+ print(idx, idx1)
52
+ ans = model.config.id2label[idx]
53
+ ans1 = model.config.id2label[idx1]
54
+ print(ans, ans1)
55
  print('sequences:')
56
  print(generated_ids.sequences)
57
  print(generated_ids)
 
88
 
89
  # answer_git_large = generate_answer_git(git_processor_large, git_model_large, image, question)
90
 
91
+ # answer_blip_base = generate_answer_blip(blip_processor_base, blip_model_base, image, question)
92
 
93
  # answer_blip_large = generate_answer_blip(blip_processor_large, blip_model_large, image, question)
94
 
95
+ # answer_vilt = generate_answer_vilt(vilt_processor, vilt_model, image, question)
96
 
97
+ return answer_git_base
98
 
99
 
100
  examples = [["cats.jpg", "How many cats are there?"], ["stop_sign.png", "What's behind the stop sign?"], ["astronaut.jpg", "What's the astronaut riding on?"]]