nielsr HF staff commited on
Commit
ef3fe9c
1 Parent(s): 0f2cfb8

Add dataset card

Browse files
Files changed (1) hide show
  1. README.md +29 -0
README.md ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ This repository contains the mapping from integer id's to actual label names (in HuggingFace Transformers typically called `id2label`) for several datasets.
2
+
3
+ Current datasets include:
4
+ - ImageNet-1k
5
+ - ImageNet-22k
6
+ - COCO detection
7
+
8
+ You can read in a label file as follows (using the `huggingface_hub` library):
9
+
10
+ ```
11
+ from huggingface_hub import hf_hub_url, cached_download
12
+ import json
13
+
14
+ REPO_ID = "datasets/huggingface/label-files"
15
+ FILENAME = "imagenet-22k-id2label.json"
16
+ id2label = json.load(open(cached_download(hf_hub_url(REPO_ID, FILENAME)), "r"))
17
+ id2label = {int(k):v for k,v in id2label.items()}
18
+ ```
19
+
20
+ 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:
21
+ ```
22
+ import json
23
+
24
+ # simple example
25
+ id2label = {0: 'cat', 1: 'dog'}
26
+
27
+ with open('cats-and-dogs-id2label.json', 'w') as fp:
28
+ json.dump(id2label, fp)
29
+ ```