forked from immich-app/immich
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ml): export clip models to ONNX and host models on Hugging Face (i…
…mmich-app#4700) * export clip models * export to hf refactored export code * export mclip, general refactoring cleanup * updated conda deps * do transforms with pillow and numpy, add tokenization config to export, general refactoring * moved conda dockerfile, re-added poetry * minor fixes * updated link * updated tests * removed `requirements.txt` from workflow * fixed mimalloc path * removed torchvision * cleaner np typing * review suggestions * update default model name * update test
- Loading branch information
Showing
29 changed files
with
6,196 additions
and
2,047 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 |
---|---|---|
@@ -1,3 +1,25 @@ | ||
from .clip import CLIPEncoder | ||
from typing import Any | ||
|
||
from app.schemas import ModelType | ||
|
||
from .base import InferenceModel | ||
from .clip import MCLIPEncoder, OpenCLIPEncoder, is_mclip, is_openclip | ||
from .facial_recognition import FaceRecognizer | ||
from .image_classification import ImageClassifier | ||
|
||
|
||
def from_model_type(model_type: ModelType, model_name: str, **model_kwargs: Any) -> InferenceModel: | ||
match model_type: | ||
case ModelType.CLIP: | ||
if is_openclip(model_name): | ||
return OpenCLIPEncoder(model_name, **model_kwargs) | ||
elif is_mclip(model_name): | ||
return MCLIPEncoder(model_name, **model_kwargs) | ||
else: | ||
raise ValueError(f"Unknown CLIP model {model_name}") | ||
case ModelType.FACIAL_RECOGNITION: | ||
return FaceRecognizer(model_name, **model_kwargs) | ||
case ModelType.IMAGE_CLASSIFICATION: | ||
return ImageClassifier(model_name, **model_kwargs) | ||
case _: | ||
raise ValueError(f"Unknown model type {model_type}") |
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
Oops, something went wrong.