-
Notifications
You must be signed in to change notification settings - Fork 243
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
46 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from abc import ABC, abstractmethod | ||
from PIL import Image | ||
from typing import Dict | ||
|
||
import importlib | ||
|
||
AVAILABLE_MODELS: Dict[str, str] = { | ||
"otter": "Otter", | ||
"idefics": "Idefics", | ||
"idefics_otter": "IdeficsOtter", | ||
} | ||
|
||
|
||
class Model(ABC): | ||
def __init__(self, name: str, model_path: str): | ||
self.name = name | ||
self.model_path = model_path | ||
|
||
@abstractmethod | ||
def generate(self, question: str, raw_image_data: Image.Image): | ||
pass | ||
|
||
|
||
def load_model(model_name: str, dataset_args: Dict[str, str]) -> Model: | ||
assert model_name in AVAILABLE_MODELS, f"{model_name} is not an available model." | ||
module_path = "pipeline.evaluation.models." + model_name | ||
dataset_name = AVAILABLE_MODELS[model_name] | ||
imported_module = importlib.import_module(module_path) | ||
dataset_class = getattr(imported_module, dataset_name) | ||
print(f"Imported class: {dataset_class}") | ||
return dataset_class(**dataset_args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters