Last active
April 26, 2022 13:50
-
-
Save iaverypadberg/5e9f89e126ee41977eb93f5b7c9c831b to your computer and use it in GitHub Desktop.
Remove annotation label from an xml file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import xml.etree.ElementTree as ET | |
from glob import glob | |
labels = [ | |
"labels", | |
"to", | |
"be", | |
"removed"] | |
files = glob('directory/with/xml/files/*.xml') | |
for file in files: | |
tree = ET.parse(file) | |
root = tree.getroot() | |
objects = root.findall('object') | |
changed = False | |
for object in objects: | |
label = object.find('name').text | |
if(label in labels): | |
root.remove(object) | |
changed=True | |
if changed: | |
tree.write(file) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment