Download pln_pytorch_model/dataset/find_classes.py from Shengzhen/PLN: direct link, hf CLI and curl.
- Browser
- Download file 797 Bytes
-
https://huggingface.co/Shengzhen/PLN/resolve/main/pln_pytorch_model/dataset/find_classes.py
- Command line
-
hf download hf://Shengzhen/PLN/pln_pytorch_model/dataset/find_classes.py
-
curl -L -o find_classes.py https://huggingface.co/Shengzhen/PLN/resolve/main/pln_pytorch_model/dataset/find_classes.py
797 Bytes
| from dataset.data import xml2dict | |
| import xml.etree.ElementTree as ET | |
| from tqdm import tqdm | |
| import json | |
| import os | |
| json_path = './classes.json' | |
| root = r'./dataset/VOC2007' | |
| annotation_root = os.path.join(root, 'Annotations') | |
| annotation_list = os.listdir(annotation_root) | |
| annotation_list = [os.path.join(annotation_root, a) for a in annotation_list] | |
| s = set() | |
| for annotation in tqdm(annotation_list): | |
| xml = ET.parse(os.path.join(annotation)).getroot() | |
| data = xml2dict(xml)['object'] | |
| if isinstance(data, list): | |
| for d in data: | |
| s.add(d['name']) | |
| else: | |
| s.add(data['name']) | |
| s = list(s) | |
| s.sort() | |
| data = {value: i for i, value in enumerate(s)} | |
| json_str = json.dumps(data) | |
| with open(json_path, 'w') as f: | |
| f.write(json_str) | |