You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何解决Google Colab加载Hugging Face数据集的文件一致性错误?

解决Hugging Face数据集下载一致性校验失败问题

在Google Colab中加载valiantlynxz/godseye-violence-detection-dataset数据集时,持续出现文件大小不一致的错误,报错代码如下:

from datasets import load_dataset

ds = load_dataset("valiantlynxz/godseye-violence-detection-dataset", download_mode="force_redownload")

Colab返回的错误信息:

OSError                                   Traceback (most recent call last)
/tmp/ipython-input-3556148243.py in <cell line: 0>()
      1 from datasets import load_dataset
      2 
----> 3 ds = load_dataset("valiantlynxz/godseye-violence-detection-dataset",download_mode="force_redownload")
      4 
      5 print(ds["train"].column_names)

26 frames
/usr/local/lib/python3.12/dist-packages/huggingface_hub/file_download.py in http_get(url, temp_file, proxies, resume_size, headers, expected_size, displayed_filename, _nb_retries, _tqdm_bar)
    523 
    524     if expected_size is not None and expected_size != temp_file.tell():
--> 525         raise EnvironmentError(
    526             consistency_error_message.format(
    527                 actual_size=temp_file.tell(),

OSError: Consistency check failed: file should be of size 12021156 but has size 10804870 (1O4KGHbRt3M_0.avi).
This is usually due to network issues while downloading the file. Please retry with `force_download=True`.

尝试清理缓存后重新加载,代码如下,但问题依旧:

from datasets import load_dataset
from huggingface_hub import snapshot_download
import shutil
import os

cache_dir = "/root/.cache/huggingface/datasets"  # default location in Colab
shutil.rmtree(cache_dir, ignore_errors=True)


hub_cache = "/root/.cache/huggingface/hub"
shutil.rmtree(hub_cache, ignore_errors=True)


ds = load_dataset("valiantlynxz/godseye-violence-detection-dataset")

以下是可行的解决方法:

  • 强制单文件重新下载:直接针对损坏的文件1O4KGHbRt3M_0.avi进行强制下载,使用huggingface_hub的download_file函数指定force_download=True:

    from huggingface_hub import download_file
    from datasets import load_dataset
    
    # 从数据集页面获取该文件的实际下载URL
    file_url = "https://huggingface.co/datasets/valiantlynxz/godseye-violence-detection-dataset/resolve/main/[对应文件路径]/1O4KGHbRt3M_0.avi"
    cache_dir = "/root/.cache/huggingface/datasets"
    
    download_file(file_url, cache_dir=cache_dir, force_download=True)
    ds = load_dataset("valiantlynxz/godseye-violence-detection-dataset")
    
  • 切换Colab运行时:重启Colab会话,或更换硬件加速选项(如从GPU切换到CPU再切回),尝试连接不同的网络节点重新下载。

  • 手动下载后本地加载:

    1. 从Hugging Face数据集页面手动下载完整数据集压缩包。
    2. 将压缩包上传到Colab的Google Drive或本地文件系统并解压。
    3. 从本地路径加载数据集:
      from datasets import load_dataset
      ds = load_dataset("/content/drive/MyDrive/解压后的数据集路径")
      
  • 联系数据集作者:若多次尝试仍报错,可能是数据集源文件本身损坏,可在数据集页面提交issue联系作者确认文件完整性。

内容的提问来源于stack exchange,提问作者AlecArk

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 11:59:58