Spaces:
Sleeping
Sleeping
Update my_model/KBVQA.py
Browse files- my_model/KBVQA.py +7 -6
my_model/KBVQA.py
CHANGED
|
@@ -11,7 +11,7 @@ from my_model.object_detection import ObjectDetector
|
|
| 11 |
import my_model.config.kbvqa_config as config
|
| 12 |
|
| 13 |
|
| 14 |
-
class KBVQA():
|
| 15 |
"""
|
| 16 |
The KBVQA class encapsulates the functionality for the Knowledge-Based Visual Question Answering (KBVQA) model.
|
| 17 |
It integrates various components such as an image captioning model, object detection model, and a fine-tuned
|
|
@@ -48,7 +48,8 @@ class KBVQA():
|
|
| 48 |
"""
|
| 49 |
|
| 50 |
def __init__(self):
|
| 51 |
-
|
|
|
|
| 52 |
self.kbvqa_model_name: str = config.KBVQA_MODEL_NAME
|
| 53 |
self.quantization: str = config.QUANTIZATION
|
| 54 |
self.max_context_window: int = config.MAX_CONTEXT_WINDOW
|
|
@@ -269,14 +270,14 @@ def prepare_kbvqa_model(only_reload_detection_model: bool = False) -> KBVQA:
|
|
| 269 |
with st.spinner('Loading model...'):
|
| 270 |
|
| 271 |
if not only_reload_detection_model:
|
| 272 |
-
|
| 273 |
-
progress_bar =
|
| 274 |
kbvqa.load_detector(kbvqa.detection_model)
|
| 275 |
progress_bar.progress(33)
|
| 276 |
kbvqa.load_caption_model()
|
| 277 |
free_gpu_resources()
|
| 278 |
progress_bar.progress(75)
|
| 279 |
-
|
| 280 |
kbvqa.load_fine_tuned_model()
|
| 281 |
free_gpu_resources()
|
| 282 |
progress_bar.progress(100)
|
|
@@ -286,7 +287,7 @@ def prepare_kbvqa_model(only_reload_detection_model: bool = False) -> KBVQA:
|
|
| 286 |
progress_bar.progress(100)
|
| 287 |
|
| 288 |
if kbvqa.all_models_loaded:
|
| 289 |
-
|
| 290 |
kbvqa.kbvqa_model.eval()
|
| 291 |
free_gpu_resources()
|
| 292 |
return kbvqa
|
|
|
|
| 11 |
import my_model.config.kbvqa_config as config
|
| 12 |
|
| 13 |
|
| 14 |
+
class KBVQA(StateManager):
|
| 15 |
"""
|
| 16 |
The KBVQA class encapsulates the functionality for the Knowledge-Based Visual Question Answering (KBVQA) model.
|
| 17 |
It integrates various components such as an image captioning model, object detection model, and a fine-tuned
|
|
|
|
| 48 |
"""
|
| 49 |
|
| 50 |
def __init__(self):
|
| 51 |
+
|
| 52 |
+
super().__init__()
|
| 53 |
self.kbvqa_model_name: str = config.KBVQA_MODEL_NAME
|
| 54 |
self.quantization: str = config.QUANTIZATION
|
| 55 |
self.max_context_window: int = config.MAX_CONTEXT_WINDOW
|
|
|
|
| 270 |
with st.spinner('Loading model...'):
|
| 271 |
|
| 272 |
if not only_reload_detection_model:
|
| 273 |
+
self.col1.text('this should take no more than a few minutes!')
|
| 274 |
+
progress_bar = self.col1.progress(0)
|
| 275 |
kbvqa.load_detector(kbvqa.detection_model)
|
| 276 |
progress_bar.progress(33)
|
| 277 |
kbvqa.load_caption_model()
|
| 278 |
free_gpu_resources()
|
| 279 |
progress_bar.progress(75)
|
| 280 |
+
self.col1.text('Almost there :)')
|
| 281 |
kbvqa.load_fine_tuned_model()
|
| 282 |
free_gpu_resources()
|
| 283 |
progress_bar.progress(100)
|
|
|
|
| 287 |
progress_bar.progress(100)
|
| 288 |
|
| 289 |
if kbvqa.all_models_loaded:
|
| 290 |
+
self.col1.success('Model loaded successfully and ready for inferecne!')
|
| 291 |
kbvqa.kbvqa_model.eval()
|
| 292 |
free_gpu_resources()
|
| 293 |
return kbvqa
|