"git@developer.sourcefind.cn:chenpangpang/transformers.git" did not exist on "2b9513fdabbcfd3ca5d7003a955be633a2f365fc"
Unverified Commit f6f6866e authored by Julien Chaumond's avatar Julien Chaumond Committed by GitHub
Browse files

`cached_download ∘ hf_hub_url` is `hf_hub_download` (#16375)

parent c88ff66c
...@@ -24,7 +24,7 @@ from datasets import load_dataset ...@@ -24,7 +24,7 @@ from datasets import load_dataset
from PIL import Image from PIL import Image
import requests import requests
from huggingface_hub import cached_download, hf_hub_url from huggingface_hub import hf_hub_download
from transformers import ( from transformers import (
BeitConfig, BeitConfig,
BeitFeatureExtractor, BeitFeatureExtractor,
...@@ -188,7 +188,7 @@ def convert_beit_checkpoint(checkpoint_url, pytorch_dump_folder_path): ...@@ -188,7 +188,7 @@ def convert_beit_checkpoint(checkpoint_url, pytorch_dump_folder_path):
config.use_relative_position_bias = True config.use_relative_position_bias = True
config.num_labels = 21841 config.num_labels = 21841
filename = "imagenet-22k-id2label.json" filename = "imagenet-22k-id2label.json"
id2label = json.load(open(cached_download(hf_hub_url(repo_id, filename)), "r")) id2label = json.load(open(hf_hub_download(repo_id, filename), "r"))
id2label = {int(k): v for k, v in id2label.items()} id2label = {int(k): v for k, v in id2label.items()}
# this dataset contains 21843 labels but the model only has 21841 # this dataset contains 21843 labels but the model only has 21841
# we delete the classes as mentioned in https://github.com/google-research/big_transfer/issues/18 # we delete the classes as mentioned in https://github.com/google-research/big_transfer/issues/18
...@@ -201,7 +201,7 @@ def convert_beit_checkpoint(checkpoint_url, pytorch_dump_folder_path): ...@@ -201,7 +201,7 @@ def convert_beit_checkpoint(checkpoint_url, pytorch_dump_folder_path):
config.use_relative_position_bias = True config.use_relative_position_bias = True
config.num_labels = 1000 config.num_labels = 1000
filename = "imagenet-1k-id2label.json" filename = "imagenet-1k-id2label.json"
id2label = json.load(open(cached_download(hf_hub_url(repo_id, filename)), "r")) id2label = json.load(open(hf_hub_download(repo_id, filename), "r"))
id2label = {int(k): v for k, v in id2label.items()} id2label = {int(k): v for k, v in id2label.items()}
config.id2label = id2label config.id2label = id2label
config.label2id = {v: k for k, v in id2label.items()} config.label2id = {v: k for k, v in id2label.items()}
...@@ -214,7 +214,7 @@ def convert_beit_checkpoint(checkpoint_url, pytorch_dump_folder_path): ...@@ -214,7 +214,7 @@ def convert_beit_checkpoint(checkpoint_url, pytorch_dump_folder_path):
config.use_relative_position_bias = True config.use_relative_position_bias = True
config.num_labels = 150 config.num_labels = 150
filename = "ade20k-id2label.json" filename = "ade20k-id2label.json"
id2label = json.load(open(cached_download(hf_hub_url(repo_id, filename)), "r")) id2label = json.load(open(hf_hub_download(repo_id, filename), "r"))
id2label = {int(k): v for k, v in id2label.items()} id2label = {int(k): v for k, v in id2label.items()}
config.id2label = id2label config.id2label = id2label
config.label2id = {v: k for k, v in id2label.items()} config.label2id = {v: k for k, v in id2label.items()}
......
...@@ -25,7 +25,7 @@ import torch ...@@ -25,7 +25,7 @@ import torch
from PIL import Image from PIL import Image
import requests import requests
from huggingface_hub import cached_download, hf_hub_url from huggingface_hub import hf_hub_download
from transformers import ConvNextConfig, ConvNextFeatureExtractor, ConvNextForImageClassification from transformers import ConvNextConfig, ConvNextFeatureExtractor, ConvNextForImageClassification
from transformers.utils import logging from transformers.utils import logging
...@@ -64,7 +64,7 @@ def get_convnext_config(checkpoint_url): ...@@ -64,7 +64,7 @@ def get_convnext_config(checkpoint_url):
repo_id = "datasets/huggingface/label-files" repo_id = "datasets/huggingface/label-files"
config.num_labels = num_labels config.num_labels = num_labels
id2label = json.load(open(cached_download(hf_hub_url(repo_id, filename)), "r")) id2label = json.load(open(hf_hub_download(repo_id, filename), "r"))
id2label = {int(k): v for k, v in id2label.items()} id2label = {int(k): v for k, v in id2label.items()}
if "1k" not in checkpoint_url: if "1k" not in checkpoint_url:
# this dataset contains 21843 labels but the model only has 21841 # this dataset contains 21843 labels but the model only has 21841
......
...@@ -24,7 +24,7 @@ from PIL import Image ...@@ -24,7 +24,7 @@ from PIL import Image
import requests import requests
import timm import timm
from huggingface_hub import cached_download, hf_hub_url from huggingface_hub import hf_hub_download
from transformers import DeiTConfig, DeiTFeatureExtractor, DeiTForImageClassificationWithTeacher from transformers import DeiTConfig, DeiTFeatureExtractor, DeiTForImageClassificationWithTeacher
from transformers.utils import logging from transformers.utils import logging
...@@ -142,7 +142,7 @@ def convert_deit_checkpoint(deit_name, pytorch_dump_folder_path): ...@@ -142,7 +142,7 @@ def convert_deit_checkpoint(deit_name, pytorch_dump_folder_path):
config.num_labels = 1000 config.num_labels = 1000
repo_id = "datasets/huggingface/label-files" repo_id = "datasets/huggingface/label-files"
filename = "imagenet-1k-id2label.json" filename = "imagenet-1k-id2label.json"
id2label = json.load(open(cached_download(hf_hub_url(repo_id, filename)), "r")) id2label = json.load(open(hf_hub_download(repo_id, filename), "r"))
id2label = {int(k): v for k, v in id2label.items()} id2label = {int(k): v for k, v in id2label.items()}
config.id2label = id2label config.id2label = id2label
config.label2id = {v: k for k, v in id2label.items()} config.label2id = {v: k for k, v in id2label.items()}
......
...@@ -24,7 +24,7 @@ import torch ...@@ -24,7 +24,7 @@ import torch
from PIL import Image from PIL import Image
import requests import requests
from huggingface_hub import cached_download, hf_hub_url from huggingface_hub import hf_hub_download
from transformers import DetrConfig, DetrFeatureExtractor, DetrForObjectDetection, DetrForSegmentation from transformers import DetrConfig, DetrFeatureExtractor, DetrForObjectDetection, DetrForSegmentation
from transformers.utils import logging from transformers.utils import logging
...@@ -196,7 +196,7 @@ def convert_detr_checkpoint(model_name, pytorch_dump_folder_path): ...@@ -196,7 +196,7 @@ def convert_detr_checkpoint(model_name, pytorch_dump_folder_path):
config.num_labels = 91 config.num_labels = 91
repo_id = "datasets/huggingface/label-files" repo_id = "datasets/huggingface/label-files"
filename = "coco-detection-id2label.json" filename = "coco-detection-id2label.json"
id2label = json.load(open(cached_download(hf_hub_url(repo_id, filename)), "r")) id2label = json.load(open(hf_hub_download(repo_id, filename), "r"))
id2label = {int(k): v for k, v in id2label.items()} id2label = {int(k): v for k, v in id2label.items()}
config.id2label = id2label config.id2label = id2label
config.label2id = {v: k for k, v in id2label.items()} config.label2id = {v: k for k, v in id2label.items()}
......
...@@ -23,7 +23,7 @@ import torch ...@@ -23,7 +23,7 @@ import torch
from PIL import Image from PIL import Image
import requests import requests
from huggingface_hub import cached_download, hf_hub_url from huggingface_hub import hf_hub_download
from transformers import BeitConfig, BeitFeatureExtractor, BeitForImageClassification, BeitForMaskedImageModeling from transformers import BeitConfig, BeitFeatureExtractor, BeitForImageClassification, BeitForMaskedImageModeling
from transformers.utils import logging from transformers.utils import logging
...@@ -151,7 +151,7 @@ def convert_dit_checkpoint(checkpoint_url, pytorch_dump_folder_path, push_to_hub ...@@ -151,7 +151,7 @@ def convert_dit_checkpoint(checkpoint_url, pytorch_dump_folder_path, push_to_hub
config.num_labels = 16 config.num_labels = 16
repo_id = "datasets/huggingface/label-files" repo_id = "datasets/huggingface/label-files"
filename = "rvlcdip-id2label.json" filename = "rvlcdip-id2label.json"
id2label = json.load(open(cached_download(hf_hub_url(repo_id, filename)), "r")) id2label = json.load(open(hf_hub_download(repo_id, filename), "r"))
id2label = {int(k): v for k, v in id2label.items()} id2label = {int(k): v for k, v in id2label.items()}
config.id2label = id2label config.id2label = id2label
config.label2id = {v: k for k, v in id2label.items()} config.label2id = {v: k for k, v in id2label.items()}
......
...@@ -26,7 +26,7 @@ from PIL import Image ...@@ -26,7 +26,7 @@ from PIL import Image
import haiku as hk import haiku as hk
import requests import requests
from huggingface_hub import cached_download, hf_hub_url from huggingface_hub import hf_hub_download
from transformers import ( from transformers import (
PerceiverConfig, PerceiverConfig,
PerceiverFeatureExtractor, PerceiverFeatureExtractor,
...@@ -318,7 +318,7 @@ def convert_perceiver_checkpoint(pickle_file, pytorch_dump_folder_path, architec ...@@ -318,7 +318,7 @@ def convert_perceiver_checkpoint(pickle_file, pytorch_dump_folder_path, architec
# set labels # set labels
config.num_labels = 1000 config.num_labels = 1000
filename = "imagenet-1k-id2label.json" filename = "imagenet-1k-id2label.json"
id2label = json.load(open(cached_download(hf_hub_url(repo_id, filename)), "r")) id2label = json.load(open(hf_hub_download(repo_id, filename), "r"))
id2label = {int(k): v for k, v in id2label.items()} id2label = {int(k): v for k, v in id2label.items()}
config.id2label = id2label config.id2label = id2label
config.label2id = {v: k for k, v in id2label.items()} config.label2id = {v: k for k, v in id2label.items()}
...@@ -367,7 +367,7 @@ def convert_perceiver_checkpoint(pickle_file, pytorch_dump_folder_path, architec ...@@ -367,7 +367,7 @@ def convert_perceiver_checkpoint(pickle_file, pytorch_dump_folder_path, architec
model = PerceiverForMultimodalAutoencoding(config) model = PerceiverForMultimodalAutoencoding(config)
# set labels # set labels
filename = "kinetics700-id2label.json" filename = "kinetics700-id2label.json"
id2label = json.load(open(cached_download(hf_hub_url(repo_id, filename)), "r")) id2label = json.load(open(hf_hub_download(repo_id, filename), "r"))
id2label = {int(k): v for k, v in id2label.items()} id2label = {int(k): v for k, v in id2label.items()}
config.id2label = id2label config.id2label = id2label
config.label2id = {v: k for k, v in id2label.items()} config.label2id = {v: k for k, v in id2label.items()}
......
...@@ -23,7 +23,7 @@ import torch ...@@ -23,7 +23,7 @@ import torch
from PIL import Image from PIL import Image
import requests import requests
from huggingface_hub import cached_download, hf_hub_url from huggingface_hub import hf_hub_download
from transformers import PoolFormerConfig, PoolFormerFeatureExtractor, PoolFormerForImageClassification from transformers import PoolFormerConfig, PoolFormerFeatureExtractor, PoolFormerForImageClassification
from transformers.utils import logging from transformers.utils import logging
...@@ -106,7 +106,7 @@ def convert_poolformer_checkpoint(model_name, checkpoint_path, pytorch_dump_fold ...@@ -106,7 +106,7 @@ def convert_poolformer_checkpoint(model_name, checkpoint_path, pytorch_dump_fold
expected_shape = (1, 1000) expected_shape = (1, 1000)
# set config attributes # set config attributes
id2label = json.load(open(cached_download(hf_hub_url(repo_id, filename)), "r")) id2label = json.load(open(hf_hub_download(repo_id, filename), "r"))
id2label = {int(k): v for k, v in id2label.items()} id2label = {int(k): v for k, v in id2label.items()}
config.id2label = id2label config.id2label = id2label
config.label2id = {v: k for k, v in id2label.items()} config.label2id = {v: k for k, v in id2label.items()}
......
...@@ -27,7 +27,7 @@ import torch.nn as nn ...@@ -27,7 +27,7 @@ import torch.nn as nn
from torch import Tensor from torch import Tensor
import timm import timm
from huggingface_hub import cached_download, hf_hub_url from huggingface_hub import hf_hub_download
from transformers import AutoFeatureExtractor, ResNetConfig, ResNetForImageClassification from transformers import AutoFeatureExtractor, ResNetConfig, ResNetForImageClassification
from transformers.utils import logging from transformers.utils import logging
...@@ -129,7 +129,7 @@ def convert_weights_and_push(save_directory: Path, model_name: str = None, push_ ...@@ -129,7 +129,7 @@ def convert_weights_and_push(save_directory: Path, model_name: str = None, push_
repo_id = "datasets/huggingface/label-files" repo_id = "datasets/huggingface/label-files"
num_labels = num_labels num_labels = num_labels
id2label = json.load(open(cached_download(hf_hub_url(repo_id, filename)), "r")) id2label = json.load(open(hf_hub_download(repo_id, filename), "r"))
id2label = {int(k): v for k, v in id2label.items()} id2label = {int(k): v for k, v in id2label.items()}
id2label = id2label id2label = id2label
......
...@@ -24,7 +24,7 @@ import torch ...@@ -24,7 +24,7 @@ import torch
from PIL import Image from PIL import Image
import requests import requests
from huggingface_hub import cached_download, hf_hub_url from huggingface_hub import hf_hub_download
from transformers import ( from transformers import (
SegformerConfig, SegformerConfig,
SegformerFeatureExtractor, SegformerFeatureExtractor,
...@@ -151,7 +151,7 @@ def convert_segformer_checkpoint(model_name, checkpoint_path, pytorch_dump_folde ...@@ -151,7 +151,7 @@ def convert_segformer_checkpoint(model_name, checkpoint_path, pytorch_dump_folde
raise ValueError(f"Model {model_name} not supported") raise ValueError(f"Model {model_name} not supported")
# set config attributes # set config attributes
id2label = json.load(open(cached_download(hf_hub_url(repo_id, filename)), "r")) id2label = json.load(open(hf_hub_download(repo_id, filename), "r"))
id2label = {int(k): v for k, v in id2label.items()} id2label = {int(k): v for k, v in id2label.items()}
config.id2label = id2label config.id2label = id2label
config.label2id = {v: k for k, v in id2label.items()} config.label2id = {v: k for k, v in id2label.items()}
......
...@@ -6,7 +6,7 @@ from PIL import Image ...@@ -6,7 +6,7 @@ from PIL import Image
import requests import requests
import timm import timm
from huggingface_hub import cached_download, hf_hub_url from huggingface_hub import hf_hub_download
from transformers import AutoFeatureExtractor, SwinConfig, SwinForImageClassification from transformers import AutoFeatureExtractor, SwinConfig, SwinForImageClassification
...@@ -41,7 +41,7 @@ def get_swin_config(swin_name): ...@@ -41,7 +41,7 @@ def get_swin_config(swin_name):
num_classes = 1000 num_classes = 1000
repo_id = "datasets/huggingface/label-files" repo_id = "datasets/huggingface/label-files"
filename = "imagenet-1k-id2label.json" filename = "imagenet-1k-id2label.json"
id2label = json.load(open(cached_download(hf_hub_url(repo_id, filename)), "r")) id2label = json.load(open(hf_hub_download(repo_id, filename), "r"))
id2label = {int(k): v for k, v in id2label.items()} id2label = {int(k): v for k, v in id2label.items()}
config.id2label = id2label config.id2label = id2label
config.label2id = {v: k for k, v in id2label.items()} config.label2id = {v: k for k, v in id2label.items()}
......
...@@ -29,7 +29,7 @@ import torch ...@@ -29,7 +29,7 @@ import torch
import torch.nn as nn import torch.nn as nn
from torch import Tensor from torch import Tensor
from huggingface_hub import cached_download, hf_hub_url from huggingface_hub import cached_download, hf_hub_download
from transformers import AutoFeatureExtractor, VanConfig, VanForImageClassification from transformers import AutoFeatureExtractor, VanConfig, VanForImageClassification
from transformers.models.van.modeling_van import VanLayerScaling from transformers.models.van.modeling_van import VanLayerScaling
from transformers.utils import logging from transformers.utils import logging
...@@ -168,7 +168,7 @@ def convert_weights_and_push(save_directory: Path, model_name: str = None, push_ ...@@ -168,7 +168,7 @@ def convert_weights_and_push(save_directory: Path, model_name: str = None, push_
repo_id = "datasets/huggingface/label-files" repo_id = "datasets/huggingface/label-files"
num_labels = num_labels num_labels = num_labels
id2label = json.load(open(cached_download(hf_hub_url(repo_id, filename)), "r")) id2label = json.load(open(hf_hub_download(repo_id, filename), "r"))
id2label = {int(k): v for k, v in id2label.items()} id2label = {int(k): v for k, v in id2label.items()}
id2label = id2label id2label = id2label
......
...@@ -23,7 +23,7 @@ import torch ...@@ -23,7 +23,7 @@ import torch
from PIL import Image from PIL import Image
import requests import requests
from huggingface_hub import cached_download, hf_hub_url from huggingface_hub import hf_hub_download
from transformers import ( from transformers import (
BertTokenizer, BertTokenizer,
ViltConfig, ViltConfig,
...@@ -182,7 +182,7 @@ def convert_vilt_checkpoint(checkpoint_url, pytorch_dump_folder_path): ...@@ -182,7 +182,7 @@ def convert_vilt_checkpoint(checkpoint_url, pytorch_dump_folder_path):
config.num_labels = 3129 config.num_labels = 3129
repo_id = "datasets/huggingface/label-files" repo_id = "datasets/huggingface/label-files"
filename = "vqa2-id2label.json" filename = "vqa2-id2label.json"
id2label = json.load(open(cached_download(hf_hub_url(repo_id, filename)), "r")) id2label = json.load(open(hf_hub_download(repo_id, filename), "r"))
id2label = {int(k): v for k, v in id2label.items()} id2label = {int(k): v for k, v in id2label.items()}
config.id2label = id2label config.id2label = id2label
config.label2id = {v: k for k, v in id2label.items()} config.label2id = {v: k for k, v in id2label.items()}
......
...@@ -23,7 +23,7 @@ import torch ...@@ -23,7 +23,7 @@ import torch
from PIL import Image from PIL import Image
import requests import requests
from huggingface_hub import cached_download, hf_hub_url from huggingface_hub import hf_hub_download
from transformers import ViTConfig, ViTFeatureExtractor, ViTForImageClassification, ViTModel from transformers import ViTConfig, ViTFeatureExtractor, ViTForImageClassification, ViTModel
from transformers.utils import logging from transformers.utils import logging
...@@ -144,7 +144,7 @@ def convert_vit_checkpoint(model_name, pytorch_dump_folder_path, base_model=True ...@@ -144,7 +144,7 @@ def convert_vit_checkpoint(model_name, pytorch_dump_folder_path, base_model=True
config.num_labels = 1000 config.num_labels = 1000
repo_id = "datasets/huggingface/label-files" repo_id = "datasets/huggingface/label-files"
filename = "imagenet-1k-id2label.json" filename = "imagenet-1k-id2label.json"
id2label = json.load(open(cached_download(hf_hub_url(repo_id, filename)), "r")) id2label = json.load(open(hf_hub_download(repo_id, filename), "r"))
id2label = {int(k): v for k, v in id2label.items()} id2label = {int(k): v for k, v in id2label.items()}
config.id2label = id2label config.id2label = id2label
config.label2id = {v: k for k, v in id2label.items()} config.label2id = {v: k for k, v in id2label.items()}
......
...@@ -24,7 +24,7 @@ from PIL import Image ...@@ -24,7 +24,7 @@ from PIL import Image
import requests import requests
import timm import timm
from huggingface_hub import cached_download, hf_hub_url from huggingface_hub import hf_hub_download
from transformers import DeiTFeatureExtractor, ViTConfig, ViTFeatureExtractor, ViTForImageClassification, ViTModel from transformers import DeiTFeatureExtractor, ViTConfig, ViTFeatureExtractor, ViTForImageClassification, ViTModel
from transformers.utils import logging from transformers.utils import logging
...@@ -149,7 +149,7 @@ def convert_vit_checkpoint(vit_name, pytorch_dump_folder_path): ...@@ -149,7 +149,7 @@ def convert_vit_checkpoint(vit_name, pytorch_dump_folder_path):
config.num_labels = 1000 config.num_labels = 1000
repo_id = "datasets/huggingface/label-files" repo_id = "datasets/huggingface/label-files"
filename = "imagenet-1k-id2label.json" filename = "imagenet-1k-id2label.json"
id2label = json.load(open(cached_download(hf_hub_url(repo_id, filename)), "r")) id2label = json.load(open(hf_hub_download(repo_id, filename), "r"))
id2label = {int(k): v for k, v in id2label.items()} id2label = {int(k): v for k, v in id2label.items()}
config.id2label = id2label config.id2label = id2label
config.label2id = {v: k for k, v in id2label.items()} config.label2id = {v: k for k, v in id2label.items()}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment