huggingface 下载仓库里的内容

首先找到单个文件,点那个下载按钮可以直接下载,又可以右键+复制链接地址,然后在服务器上用 wget 等方式下载这个链接就可以了。

下面讲讲下载整个仓库:
参考:
https://blog.csdn.net/abc13526222160/article/details/134856943

先:

# 安装依赖
pip install -U huggingface_hub

再切换源为镜像站(https://hf-mirror.com/):

# 基本命令示例
export HF_ENDPOINT=https://hf-mirror.com

以下载数据集为例,注意需要指定 repo-type:

huggingface-cli download  --repo-type dataset \
--resume-download pscotti/naturalscenesdataset \
--local-dir /mnt/workspace/maxinzhu/denghan/fMRI-reconstruction-NSD/train_logs

如果仓库里无用的文件很多,我只想下载某些文件夹下的文件该怎么办?

这时候用 huggingface-cli 就不太方便了。

最后用 python 脚本下载,参考:
https://zhuanlan.zhihu.com/p/663712983

例子:
注意,用 os 更改环境变量必须在引入 huggingface_hub 之前。

allow_patterns 即指定下载的文件的匹配方式,用 folder/* 即可指定下载 folder 下的所有文件,别的正则表达式也可以。

import os
# 修改为镜像源
os.environ['HF_ENDPOINT'] = 'https://hf-mirror.com'

from huggingface_hub import snapshot_download

snapshot_download(
  repo_id="pscotti/naturalscenesdataset",
  repo_type="dataset",
  local_dir="/mnt/workspace/maxinzhu/denghan/fMRI-reconstruction-NSD/train_logs",
  allow_patterns=['mindeye_models/*'],
  local_dir_use_symlinks=False,
  resume_download=True,
#   proxies={"https": "http://localhost:7890"}, # clash default port
  max_workers=8
)
posted @ 2024-05-14 22:17  Cold_Chair  阅读(352)  评论(0编辑  收藏  举报