This repository has been archived by the owner on Apr 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
878 additions
and
55 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Script to create CSV data file from Pascal VOC annotation files | ||
# Based off code from GitHub user datitran: https://github.com/datitran/raccoon_dataset/blob/master/xml_to_csv.py | ||
|
||
import os | ||
import glob | ||
import pandas as pd | ||
import xml.etree.ElementTree as ET | ||
|
||
def xml_to_csv(path): | ||
xml_list = [] | ||
for xml_file in glob.glob(path + '/*.xml'): | ||
tree = ET.parse(xml_file) | ||
root = tree.getroot() | ||
for member in root.findall('object'): | ||
value = (root.find('filename').text, | ||
int(root.find('size')[0].text), | ||
int(root.find('size')[1].text), | ||
member[0].text, | ||
int(float(member.find('bndbox').find('xmin').text)), | ||
int(float(member.find('bndbox').find('ymin').text)), | ||
int(float(member.find('bndbox').find('xmax').text)), | ||
int(float(member.find('bndbox').find('ymax').text)) | ||
) | ||
xml_list.append(value) | ||
column_name = ['filename', 'width', 'height', 'class', 'xmin', 'ymin', 'xmax', 'ymax'] | ||
xml_df = pd.DataFrame(xml_list, columns=column_name) | ||
return xml_df | ||
|
||
def main(): | ||
for folder in ['train','validation']: | ||
image_path = os.path.join(os.getcwd(), ('images/' + folder)) | ||
xml_df = xml_to_csv(image_path) | ||
xml_df.to_csv(('images/' + folder + '_labels.csv'), index=None) | ||
print('Successfully converted xml to csv.') | ||
|
||
main() |
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
Oops, something went wrong.