mlfoundations / open_clip

An open source implementation of CLIP.
Other
9.93k stars 959 forks source link

load OpenCLIP model and tokenizer from local path #883

Open YushunXiang opened 4 months ago

YushunXiang commented 4 months ago

Load OpenCLIP model and tokenizer from local path

Usage:

model, processor = open_clip.create_model_from_pretrained(
    model_name=f'hf-hub:{model_id}',
    precision='fp16',
    cache_dir=cache_dir,
)
print(f"Loading tokenizer from {model_args.model_path}")
tokenizer = open_clip.get_tokenizer(
    model_name=f'hf-hub:{model_id}',
    cache_dir=cache_dir,
)

The cache_dir is your local path.