Skip to content

Instantly share code, notes, and snippets.

@Mahmood-Hussain
Created November 21, 2022 03:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mahmood-Hussain/1f3ab43075997e8a411191b0d404d568 to your computer and use it in GitHub Desktop.
Save Mahmood-Hussain/1f3ab43075997e8a411191b0d404d568 to your computer and use it in GitHub Desktop.
This code snippet is to remove labels (bounding boxes) marked as difficult in RTTS dataset. Please replace label_dir with original labels directory and out_dir is where to save newly modified labels.
import os
import xml.etree.ElementTree as ET
label_dir = '/home/mahmood/Downloads/RTTS/labels_original'
out_dir = '/home/mahmood/Downloads/RTTS/labels'
label_file_paths = os.listdir(label_dir)
print(f'Processing ...')
total_difficult = 0
for label_file in label_file_paths:
s = os.path.join(label_dir, label_file)
d = os.path.join(out_dir, label_file)
tree = ET.parse(s)
root = tree.getroot()
for object in root.findall('object'):
is_difficult = int(object.find('difficult').text)
if is_difficult:
total_difficult += 1
root.remove(object)
tree.write(d)
print(f'Finished. Removed total {total_difficult} difficult labels saved to {out_dir}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment