Crop images using PASCAL VOC .xml annotations

Piyush Kulkarni
2 min readMar 5, 2021

Multiple labels in an image: Spade, number 3, number 10, Queen

If you already have PASCAL VOC .xml annotations for your images and if you would want to crop the images as per the bounding boxes of the annotations, this blog is for you.

I wanted to train Hearts, Spades, Clubs and Diamonds for classification task and I had images annotated for multiple labels as shown here.

This git hub repo helped me organize the data in two formats:

  1. As per the names of the images and cropping multiple labels using main.py.
  2. Organizing the cropped images as per the labels using main_classification.ipynb.
The two type of folders created as per the image names & as per the labels

Clone the repo using:

git clone https://github.com/Piyush-Kulkarni/PascalVOC-to-Images.git

Copy paste all the images and .xml annotations in the data folder.

If you face xmltodict module not found error, install it using commands here.

Often the image classification task demands the data to be organized as per the class labels. And thus it would be useful to use annotations and crop the objects of interests.

To learn more: check out.

Written by:

Piyush Kulkarni

(Data Scientist)

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet

Write a response