Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

appeared xml_to_csv.py file #124

Open
YeonSeo-Kim opened this issue Sep 9, 2021 · 0 comments
Open

appeared xml_to_csv.py file #124

YeonSeo-Kim opened this issue Sep 9, 2021 · 0 comments

Comments

@YeonSeo-Kim
Copy link

I tried to change the xml file of the dataset of the aihub site to csv by slightly changing the code.
The code is as follows.

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 img in root.findall('image'):
            for bbox in img.findall('box'):
                value = (img.attrib['name'],
                         img.attrib['width'], img.attrib['height'], 
                         bbox.attrib['label'].replace("_", "-"),
                         bbox.attrib['xtl'],
                         bbox.attrib['ytl'],
                         bbox.attrib['xbr'],
                         bbox.attrib['ybr']
                         )
                xml_list.append(value)
    column_name = ['filename', 'width', 'height', 'class', 'xtl', 'ytl', 'xbr', 'ybr']
    xml_df = pd.DataFrame(xml_list, columns=column_name)
    return xml_df

def main():
    os.getcwd()
    os.chdir('/project/Liberty/aihub_pedestrian')
    # image_path = os.path.join(os.getcwd(), '/Bbox_1_new', '/Bbox_0001')
    image_path = '/project/Liberty/aihub_pedestrian/Bbox_1_new/Bbox_0002'
    xml_df = xml_to_csv(image_path)
    xml_df.to_csv('bbox_0002_2.csv', index=None)
    print('Successfully converted xml to csv', image_path)

main()

then, I created a tfrecord file and checked it using the code that reads the tfrecord, but there was an error that the parameter was empty. I would appreciate it if anyone could let me know if there is an error in the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant