INNER CODE UNIT · Python
_load_model
patrickjohncyh/fashion-clip · fashion_clip/fashion_clip.py:150
def _load_model(self,
name: str,
device: Union[str, torch.device] = "cuda" if torch.cuda.is_available() else "cpu",
auth_token = None):
# model is one of know HF models
if name in _MODELS or _is_hugging_face_repo(name, auth_token):
# if using know short-hand, extract from dict
name = _MODELS[name] if name in _MODELS else name
model = CLIPModel.from_pretrained(name, use_auth_token=auth_token)
preprocessing = CLIPProcessor.from_pretrained(name, use_auth_token=auth_token)
hash = _model_processor_hash(name, model, preprocessing)
# else it doesn't use HF, assume using OpenAI CLiP
else:
if os.path.isfile(name):
model_path = name
elif validators.url(name):
# generic url or S3 path