Convert COCO
to Pascal VOC
Import COCO, check the labels in the labeling toolbox, export Pascal VOC. Pascal VOC is the format that classic detection tools and the torchvision VOC loaders read.
COCO vs Pascal VOC
COCO and Pascal VOC describe the same objects in different files and notations.
| COCO | Pascal VOC | |
|---|---|---|
| Annotation files | One JSON file per dataset (annotations/instances.json) that lists images, annotations and categories. | One XML file per image in Annotations/, PNG masks in SegmentationClass/ and SegmentationObject/, image lists in ImageSets/. |
| Coordinates | Absolute pixels; bbox is [x, y, width, height], measured from the top-left corner. | Absolute pixels; a box is xmin, ymin, xmax, ymax. |
| Shapes | Boxes, polygons or RLE masks, keypoints and image captions. | Boxes in the XML; semantic and instance segmentation as PNG masks. |
| Classes | A categories list with numeric ids; every annotation points to one with its category_id. | The class name is written in each XML object; colors.txt, added by Supervisely, maps classes to mask colours. |
What the conversion changes
Between the formats
- COCO boxes become xmin, ymin, xmax, ymax in one XML file per image.
- COCO polygons are drawn into the VOC class and object PNG masks.
Import COCO
- Instances (polygons and boxes) and captions are imported; keypoints go through Import COCO Keypoints.
- Holes in polygons are kept.
- The info and licenses sections and the per-image details of the file are not imported.
Export to Pascal VOC
- Polygons, bitmaps and rectangles are exported, other shapes are skipped; only polygons and bitmaps are drawn into the masks.
- Image tags other than train and val are dropped.
- Without train and val tags the images are split 80/20.
Convert COCO to Pascal VOC in three steps
- 01
Import COCO
Upload your COCO folder or archive to Supervisely and run Import COCO from the Ecosystem: it creates a project with the images and labels (COCO import guide).
- 02
Review in the labeling toolbox
Open the project in the image labeling toolbox to check classes and fix labels before they go to Pascal VOC.
- 03
Export to Pascal VOC
Open the menu of the project, choose Download via app and run Export to Pascal VOC. The archive appears in Tasks and Team Files.
Apps in the Supervisely Ecosystem
Run this conversion on your own data in a free account, or let us walk your team through it.
Or in a few lines of Python
After the import, the Python SDK downloads the project as Supervisely JSON and writes Pascal VOC on your disk.
Install it with pip install supervisely.
import supervisely as sly
# SERVER_ADDRESS and API_TOKEN come from the environment
api = sly.Api.from_env()
# ID of the project Import COCO created
sly.download_fast(api, project_id=12345, dest_dir="sly_project")
sly.convert.project_to_pascal_voc("sly_project", "pascal_voc")Frequently asked questions.
Can I convert COCO to Pascal VOC without code?
Yes. Import the data with Import COCO, check it in the image labeling toolbox, then export it with Export to Pascal VOC. Both start from the Supervisely web interface.
What changes when COCO becomes Pascal VOC?
COCO boxes become xmin, ymin, xmax, ymax in one XML file per image. COCO polygons are drawn into the VOC class and object PNG masks. Instances (polygons and boxes) and captions are imported; keypoints go through Import COCO Keypoints.
Does Pascal VOC use the same coordinates as COCO?
Both use absolute pixel coordinates, written differently. COCO: Absolute pixels; bbox is [x, y, width, height], measured from the top-left corner. Pascal VOC: Absolute pixels; a box is xmin, ymin, xmax, ymax.
How do COCO classes carry over to Pascal VOC?
In COCO: a categories list with numeric ids; every annotation points to one with its category_id. In Pascal VOC: the class name is written in each XML object; colors.txt, added by Supervisely, maps classes to mask colours. The class names stay the same on the way through Supervisely, so rename or merge classes in the project before you export.
Can I convert COCO to Pascal VOC in Python?
After the import, the Python SDK downloads the project as Supervisely JSON and writes Pascal VOC on your disk. See the SDK export tutorial.