label-files
收藏魔搭社区2025-11-27 更新2025-06-14 收录
下载链接:
https://modelscope.cn/datasets/huggingface/label-files
下载链接
链接失效反馈官方服务:
资源简介:
This repository contains the mapping from integer id's to actual label names (in HuggingFace Transformers typically called `id2label`) for several datasets.
Current datasets include:
- ImageNet-1k
- ImageNet-22k (also called ImageNet-21k as there are 21,843 classes)
- COCO detection 2017
- COCO panoptic 2017
- ADE20k (actually, the [MIT Scene Parsing benchmark](http://sceneparsing.csail.mit.edu/), which is a subset of ADE20k)
- Cityscapes
- VQAv2
- Kinetics-700
- RVL-CDIP
- PASCAL VOC
- Kinetics-400
- ...
You can read in a label file as follows (using the `huggingface_hub` library):
```
from huggingface_hub import hf_hub_download
import json
repo_id = "huggingface/label-files"
filename = "imagenet-22k-id2label.json"
id2label = json.load(open(hf_hub_download(repo_id, filename, repo_type="dataset"), "r"))
id2label = {int(k):v for k,v in id2label.items()}
```
To add an `id2label` mapping for a new dataset, simply define a Python dictionary, and then save that dictionary as a JSON file, like so:
```
import json
# simple example
id2label = {0: 'cat', 1: 'dog'}
with open('cats-and-dogs-id2label.json', 'w') as fp:
json.dump(id2label, fp)
```
You can then upload it to this repository (assuming you have write access).
本仓库存储了多个数据集的整数ID与实际标签名称的映射关系(在HuggingFace Transformers中通常称为`id2label`)。
当前涵盖的数据集包括:
- ImageNet-1k
- ImageNet-22k(亦称ImageNet-21k,因其包含21843个类别)
- COCO 2017检测任务
- COCO 2017全景任务
- ADE20k(实则为[MIT场景解析基准数据集](http://sceneparsing.csail.mit.edu/),该数据集是ADE20k的子集)
- Cityscapes
- VQAv2
- Kinetics-700
- RVL-CDIP
- PASCAL VOC
- Kinetics-400
- ……
你可通过如下方式读取标签文件(需使用`huggingface_hub`库):
python
from huggingface_hub import hf_hub_download
import json
repo_id = "huggingface/label-files"
filename = "imagenet-22k-id2label.json"
id2label = json.load(open(hf_hub_download(repo_id, filename, repo_type="dataset"), "r"))
id2label = {int(k):v for k,v in id2label.items()}
若要为新增数据集添加`id2label`映射,仅需定义一个Python字典,并将该字典保存为JSON格式文件,示例如下:
python
import json
# 简单示例
id2label = {0: '猫', 1: '狗'}
with open('cats-and-dogs-id2label.json', 'w') as fp:
json.dump(id2label, fp)
你随后即可将其上传至本仓库(前提是你拥有该仓库的写入权限)。
提供机构:
maas
创建时间:
2025-03-12



