Created
November 21, 2022 03:24
-
-
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.
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 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