以"openai/clip-vit-large-patch14"为例,原代码为:
self.tokenizer = CLIPTokenizer.from_pretrained(“openai/clip-vit-large-patch14”)
self.transformer = CLIPTextModel.from_pretrained(“openai/clip-vit-large-patch14”)
但我连不到外网没办法直接下载,所以去
https://huggingface.co/openai/clip-vit-large-patch14/tree/main
这个网页把所有文件下载下来,传到.cache/huggingface/transformers下,然后把代码改
# 校园网连不上huggingface# self.tokenizer = CLIPTokenizer.from_pretrained(version)# self.transformer = CLIPTextModel.from_pretrained(version)local_path="/home/rongl/.cache/huggingface/transformers/{}".format(version.split('/')[-1])# '/home/xxx/.cache/huggingface/transformers/clip-vit-large-patch14'self.tokenizer = CLIPTokenizer.from_pretrained(local_path)self.transformer = CLIPTextModel.from_pretrained(local_path)