Switch from cached_download to hf_hub_download in remaining occurrences (#31284)

Switch from hf_hub_url to hf_hub_download in remaining occurences
This commit is contained in:
Lucain
2024-06-06 13:05:59 +02:00
committed by GitHub
parent 5fabd1e83b
commit 9ef93fccad
12 changed files with 29 additions and 24 deletions

View File

@@ -245,11 +245,12 @@ You'll also want to create a dictionary that maps a label id to a label class wh
```py ```py
>>> import json >>> import json
>>> from huggingface_hub import cached_download, hf_hub_url >>> from pathlib import Path
>>> from huggingface_hub import hf_hub_download
>>> repo_id = "huggingface/label-files" >>> repo_id = "huggingface/label-files"
>>> filename = "ade20k-id2label.json" >>> filename = "ade20k-id2label.json"
>>> id2label = json.load(open(cached_download(hf_hub_url(repo_id, filename, repo_type="dataset")), "r")) >>> id2label = json.loads(Path(hf_hub_download(repo_id, filename, repo_type="dataset")).read_text())
>>> id2label = {int(k): v for k, v in id2label.items()} >>> id2label = {int(k): v for k, v in id2label.items()}
>>> label2id = {v: k for k, v in id2label.items()} >>> label2id = {v: k for k, v in id2label.items()}
>>> num_labels = len(id2label) >>> num_labels = len(id2label)

View File

@@ -83,11 +83,12 @@ pip install -q datasets transformers evaluate
```py ```py
>>> import json >>> import json
>>> from huggingface_hub import cached_download, hf_hub_url >>> from pathlib import Path
>>> from huggingface_hub import hf_hub_download
>>> repo_id = "huggingface/label-files" >>> repo_id = "huggingface/label-files"
>>> filename = "ade20k-id2label.json" >>> filename = "ade20k-id2label.json"
>>> id2label = json.load(open(cached_download(hf_hub_url(repo_id, filename, repo_type="dataset")), "r")) >>> id2label = json.loads(Path(hf_hub_download(repo_id, filename, repo_type="dataset")).read_text())
>>> id2label = {int(k): v for k, v in id2label.items()} >>> id2label = {int(k): v for k, v in id2label.items()}
>>> label2id = {v: k for k, v in id2label.items()} >>> label2id = {v: k for k, v in id2label.items()}
>>> num_labels = len(id2label) >>> num_labels = len(id2label)

View File

@@ -83,11 +83,12 @@ pip install -q datasets transformers evaluate
```py ```py
>>> import json >>> import json
>>> from huggingface_hub import cached_download, hf_hub_url >>> from pathlib import Path
>>> from huggingface_hub import hf_hub_download
>>> repo_id = "huggingface/label-files" >>> repo_id = "huggingface/label-files"
>>> filename = "ade20k-id2label.json" >>> filename = "ade20k-id2label.json"
>>> id2label = json.load(open(cached_download(hf_hub_url(repo_id, filename, repo_type="dataset")), "r")) >>> id2label = json.loads(Path(hf_hub_download(repo_id, filename, repo_type="dataset")).read_text())
>>> id2label = {int(k): v for k, v in id2label.items()} >>> id2label = {int(k): v for k, v in id2label.items()}
>>> label2id = {v: k for k, v in id2label.items()} >>> label2id = {v: k for k, v in id2label.items()}
>>> num_labels = len(id2label) >>> num_labels = len(id2label)

View File

@@ -82,11 +82,12 @@ pip install -q datasets transformers evaluate
```py ```py
>>> import json >>> import json
>>> from huggingface_hub import cached_download, hf_hub_url >>> from pathlib import Path
>>> from huggingface_hub import hf_hub_download
>>> repo_id = "huggingface/label-files" >>> repo_id = "huggingface/label-files"
>>> filename = "ade20k-id2label.json" >>> filename = "ade20k-id2label.json"
>>> id2label = json.load(open(cached_download(hf_hub_url(repo_id, filename, repo_type="dataset")), "r")) >>> id2label = json.loads(Path(hf_hub_download(repo_id, filename, repo_type="dataset")).read_text())
>>> id2label = {int(k): v for k, v in id2label.items()} >>> id2label = {int(k): v for k, v in id2label.items()}
>>> label2id = {v: k for k, v in id2label.items()} >>> label2id = {v: k for k, v in id2label.items()}
>>> num_labels = len(id2label) >>> num_labels = len(id2label)

View File

@@ -19,9 +19,10 @@ URL: https://github.com/microsoft/CvT"""
import argparse import argparse
import json import json
from collections import OrderedDict from collections import OrderedDict
from pathlib import Path
import torch import torch
from huggingface_hub import cached_download, hf_hub_url from huggingface_hub import hf_hub_download
from transformers import AutoImageProcessor, CvtConfig, CvtForImageClassification from transformers import AutoImageProcessor, CvtConfig, CvtForImageClassification
@@ -283,7 +284,7 @@ def convert_cvt_checkpoint(cvt_model, image_size, cvt_file_name, pytorch_dump_fo
repo_id = "huggingface/label-files" repo_id = "huggingface/label-files"
num_labels = num_labels num_labels = num_labels
id2label = json.load(open(cached_download(hf_hub_url(repo_id, img_labels_file, repo_type="dataset")), "r")) id2label = json.loads(Path(hf_hub_download(repo_id, img_labels_file, repo_type="dataset")).read_text())
id2label = {int(k): v for k, v in id2label.items()} id2label = {int(k): v for k, v in id2label.items()}
id2label = id2label id2label = id2label

View File

@@ -20,7 +20,7 @@ from pathlib import Path
import requests import requests
import torch import torch
from huggingface_hub import cached_download, hf_hub_url from huggingface_hub import hf_hub_download
from PIL import Image from PIL import Image
from transformers import DeformableDetrConfig, DeformableDetrForObjectDetection, DeformableDetrImageProcessor from transformers import DeformableDetrConfig, DeformableDetrForObjectDetection, DeformableDetrImageProcessor
@@ -109,7 +109,7 @@ def convert_deformable_detr_checkpoint(
config.num_labels = 91 config.num_labels = 91
repo_id = "huggingface/label-files" repo_id = "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, repo_type="dataset")), "r")) id2label = json.loads(Path(hf_hub_download(repo_id, filename, repo_type="dataset")).read_text())
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()}

View File

@@ -22,7 +22,7 @@ from pathlib import Path
import requests import requests
import torch import torch
from huggingface_hub import cached_download, hf_hub_download, hf_hub_url from huggingface_hub import hf_hub_download
from PIL import Image from PIL import Image
from transformers import DetaConfig, DetaForObjectDetection, DetaImageProcessor from transformers import DetaConfig, DetaForObjectDetection, DetaImageProcessor
@@ -48,7 +48,7 @@ def get_deta_config():
config.num_labels = 91 config.num_labels = 91
repo_id = "huggingface/label-files" repo_id = "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, repo_type="dataset")), "r")) id2label = json.loads(Path(hf_hub_download(repo_id, filename, repo_type="dataset")).read_text())
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()}

View File

@@ -22,7 +22,7 @@ from pathlib import Path
import requests import requests
import torch import torch
from huggingface_hub import cached_download, hf_hub_download, hf_hub_url from huggingface_hub import hf_hub_download
from PIL import Image from PIL import Image
from transformers import DetaConfig, DetaForObjectDetection, DetaImageProcessor, SwinConfig from transformers import DetaConfig, DetaForObjectDetection, DetaImageProcessor, SwinConfig
@@ -63,7 +63,7 @@ def get_deta_config(model_name):
filename = "coco-detection-id2label.json" filename = "coco-detection-id2label.json"
config.num_labels = num_labels config.num_labels = num_labels
id2label = json.load(open(cached_download(hf_hub_url(repo_id, filename, repo_type="dataset")), "r")) id2label = json.loads(Path(hf_hub_download(repo_id, filename, repo_type="dataset")).read_text())
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()}

View File

@@ -20,7 +20,7 @@ from pathlib import Path
import requests import requests
import torch import torch
from huggingface_hub import cached_download, hf_hub_url from huggingface_hub import hf_hub_download
from PIL import Image from PIL import Image
from transformers import DPTConfig, DPTForDepthEstimation, DPTForSemanticSegmentation, DPTImageProcessor from transformers import DPTConfig, DPTForDepthEstimation, DPTForSemanticSegmentation, DPTImageProcessor
@@ -61,7 +61,7 @@ def get_dpt_config(checkpoint_url):
config.patch_size = 16 config.patch_size = 16
repo_id = "huggingface/label-files" repo_id = "huggingface/label-files"
filename = "ade20k-id2label.json" filename = "ade20k-id2label.json"
id2label = json.load(open(cached_download(hf_hub_url(repo_id, filename, repo_type="dataset")), "r")) id2label = json.loads(Path(hf_hub_download(repo_id, filename, repo_type="dataset")).read_text())
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()}

View File

@@ -20,7 +20,7 @@ from pathlib import Path
import requests import requests
import torch import torch
from huggingface_hub import cached_download, hf_hub_url from huggingface_hub import hf_hub_download
from PIL import Image from PIL import Image
from transformers import DPTConfig, DPTForDepthEstimation, DPTForSemanticSegmentation, DPTImageProcessor from transformers import DPTConfig, DPTForDepthEstimation, DPTForSemanticSegmentation, DPTImageProcessor
@@ -49,7 +49,7 @@ def get_dpt_config(checkpoint_url):
config.num_labels = 150 config.num_labels = 150
repo_id = "huggingface/label-files" repo_id = "huggingface/label-files"
filename = "ade20k-id2label.json" filename = "ade20k-id2label.json"
id2label = json.load(open(cached_download(hf_hub_url(repo_id, filename, repo_type="dataset")), "r")) id2label = json.loads(Path(hf_hub_download(repo_id, filename, repo_type="dataset")).read_text())
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()}

View File

@@ -30,7 +30,7 @@ from typing import Dict, List, Tuple
import torch import torch
import torch.nn as nn import torch.nn as nn
from classy_vision.models.regnet import RegNet, RegNetParams from classy_vision.models.regnet import RegNet, RegNetParams
from huggingface_hub import cached_download, hf_hub_url from huggingface_hub import hf_hub_download
from torch import Tensor from torch import Tensor
from vissl.models.model_helpers import get_trunk_forward_outputs from vissl.models.model_helpers import get_trunk_forward_outputs
@@ -165,7 +165,7 @@ def convert_weights_and_push(save_directory: Path, model_name: str = None, push_
repo_id = "huggingface/label-files" repo_id = "huggingface/label-files"
num_labels = num_labels num_labels = num_labels
id2label = json.load(open(cached_download(hf_hub_url(repo_id, filename, repo_type="dataset")), "r")) id2label = json.loads(Path(hf_hub_download(repo_id, filename, repo_type="dataset")).read_text())
id2label = {int(k): v for k, v in id2label.items()} id2label = {int(k): v for k, v in id2label.items()}
id2label = id2label id2label = id2label

View File

@@ -25,7 +25,7 @@ import timm
import torch import torch
import torch.nn as nn import torch.nn as nn
from classy_vision.models.regnet import RegNet, RegNetParams, RegNetY32gf, RegNetY64gf, RegNetY128gf from classy_vision.models.regnet import RegNet, RegNetParams, RegNetY32gf, RegNetY64gf, RegNetY128gf
from huggingface_hub import cached_download, hf_hub_url from huggingface_hub import hf_hub_download
from torch import Tensor from torch import Tensor
from vissl.models.model_helpers import get_trunk_forward_outputs from vissl.models.model_helpers import get_trunk_forward_outputs
@@ -225,7 +225,7 @@ def convert_weights_and_push(save_directory: Path, model_name: str = None, push_
repo_id = "huggingface/label-files" repo_id = "huggingface/label-files"
num_labels = num_labels num_labels = num_labels
id2label = json.load(open(cached_download(hf_hub_url(repo_id, filename, repo_type="dataset")), "r")) id2label = json.loads(Path(hf_hub_download(repo_id, filename, repo_type="dataset")).read_text())
id2label = {int(k): v for k, v in id2label.items()} id2label = {int(k): v for k, v in id2label.items()}
id2label = id2label id2label = id2label