pascal
Python utility to work with PascalVoc annotation format
Image examples from PascalVoc2007 dataset
Code Example
import json
from pathlib import Path
from PIL import Image
from pascal import annotation_from_xml
from pascal.utils import save_xml
ds_path = Path("/home/VOCtest_06-Nov-2007/VOCdevkit/VOC2007")
img_src = ds_path / "JPEGImages"
ann_src = ds_path / "Annotations"
out_labelme = ds_path / "converted_labelme"
attr_type_spec = {"truncated": bool, "difficult": bool}
label_map = {"car": 1, "dog": 0, "person": 2, "train": 3}
if __name__ == "__main__":
for file in img_src.glob("*.jpg"):
# Get annotation file path
ann_file = (ann_src / file.name).with_suffix(".xml")
# Make pascal annotation object
ann = annotation_from_xml(ann_file, attr_type_spec)
print(ann)
# Save to xml file (same as ann_file)
xml = ann.to_xml()
out_xml_name = file.with_suffix(".xml").name
save_xml(out_xml_name, xml)
# Save yolo annotation
yolo_ann = ann.to_yolo(label_map)
out_yolo_name = file.with_suffix(".txt").name
with open(out_yolo_name, "w") as f:
f.write(yolo_ann)
# Convert to labelme and save json file
res = ann.to_labelme(file, save_img_data=False)
with open((out_labelme / file.name).with_suffix(".json"), "w") as f:
json.dump(res, f, indent=2)
# Draw objects
img = Image.open(file)
draw_img = ann.draw_boxes(img)
draw_img.show()
Visualization example:
draw_img = ann.draw_boxes(img)
draw_img.show()
Installation
From source
python setup.py install
Using pip
pip install pascal-voc
Metadata
Release files for pascal-voc 2.1.12
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pascal_voc-2.1.12-py3-none-any.whl | Python 3 | none | any | Details for pascal_voc-2.1.12-py3-none-any.whl |
Release files / pascal_voc-2.1.12-py3-none-any.whl
| Download URL | pascal_voc-2.1.12-py3-none-any.whl |
|---|---|
| Size | 427.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5ea5b8ae4c99af4c13706bdf73dfda5f0df48279ad9054716117a70d8162ae02
|
|
BLAKE2b-256 checksum How to use checksums |
15eed9890270c5be45fadb8ff3baa4942503e5dc70a5492ea24bc5c796bd2d67
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.3
|
Security for pascal-voc 2.1.12
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.