MinxuanQin commited on
Commit
7b4b5f6
1 Parent(s): d43497c

fix error in vbert; add time counter

Browse files
Files changed (2) hide show
  1. app.py +7 -2
  2. model_loader.py +2 -1
app.py CHANGED
@@ -4,6 +4,7 @@ sys.path.append(".")
4
  import streamlit as st
5
  import pandas as pd
6
  from PIL import Image
 
7
 
8
  from model_loader import *
9
  from datasets import load_dataset
@@ -21,7 +22,7 @@ model_name = st.sidebar.selectbox(
21
  )
22
 
23
  image_selector_unspecific = st.number_input(
24
- "Select an image id: ",
25
  0, len(df)
26
  )
27
 
@@ -38,7 +39,11 @@ label = sample['label']
38
  # inference
39
  question = st.text_input(f"Ask the model a question related to the image: \n"
40
  f"(e.g. \"{sample['ques']}\")")
 
 
41
  args = load_model(model_name) # TODO: cache
42
  answer = get_answer(args, image, question, model_name)
 
43
  st.text(f"Answer by {model_name}: {answer}")
44
- st.text(f"Ground truth (of the example): {label}")
 
 
4
  import streamlit as st
5
  import pandas as pd
6
  from PIL import Image
7
+ import time
8
 
9
  from model_loader import *
10
  from datasets import load_dataset
 
22
  )
23
 
24
  image_selector_unspecific = st.number_input(
25
+ "Select an question id: ",
26
  0, len(df)
27
  )
28
 
 
39
  # inference
40
  question = st.text_input(f"Ask the model a question related to the image: \n"
41
  f"(e.g. \"{sample['ques']}\")")
42
+
43
+ t_begin = time.perf_counter()
44
  args = load_model(model_name) # TODO: cache
45
  answer = get_answer(args, image, question, model_name)
46
+ t_end = time.perf_counter()
47
  st.text(f"Answer by {model_name}: {answer}")
48
+ st.text(f"Ground truth (of the example): {label}")
49
+ st.text(f"Time consumption: {(t_end-t_begin): .4f} s")
model_loader.py CHANGED
@@ -189,7 +189,8 @@ def get_answer(model_loader_args, img, question, model_name):
189
  vqa_answers = get_data(VQA_URL)
190
  try:
191
  # load question and image (processor = tokenizer)
192
- _, inputs = get_item(img, question, processor, model_name)
 
193
  outputs = model(**inputs)
194
  except Exception:
195
  return err_msg()
 
189
  vqa_answers = get_data(VQA_URL)
190
  try:
191
  # load question and image (processor = tokenizer)
192
+ ## MOD Minxuan: fix error
193
+ _, inputs = get_item(img, question, processor, "resnet50")
194
  outputs = model(**inputs)
195
  except Exception:
196
  return err_msg()