EdjeElectronics/TensorFlow-Lite-Object-Detection-on-Android-and-Raspberry-Pi

images/val folder not found

muhd360 opened this issue · 3 comments

image
Traceback (most recent call last):
File "/content/create_csv.py", line 36, in
main()
File "/content/create_csv.py", line 32, in main
xml_df = xml_to_csv(image_path)
File "/content/create_csv.py", line 19, in xml_to_csv
int(member[4][0].text),
IndexError: child index out of range
Traceback (most recent call last):
File "/content/create_tfrecord.py", line 120, in
tf.app.run()
File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/platform/app.py", line 36, in run
_run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef)
File "/usr/local/lib/python3.10/dist-packages/absl/app.py", line 308, in run
_run_main(main, args)
File "/usr/local/lib/python3.10/dist-packages/absl/app.py", line 254, in _run_main
sys.exit(main(argv))
File "/content/create_tfrecord.py", line 93, in main
examples = pd.read_csv(FLAGS.csv_input)
File "/usr/local/lib/python3.10/dist-packages/pandas/io/parsers/readers.py", line 912, in read_csv
return _read(filepath_or_buffer, kwds)
File "/usr/local/lib/python3.10/dist-packages/pandas/io/parsers/readers.py", line 577, in _read
parser = TextFileReader(filepath_or_buffer, **kwds)
File "/usr/local/lib/python3.10/dist-packages/pandas/io/parsers/readers.py", line 1407, in init
self._engine = self._make_engine(f, self.engine)
File "/usr/local/lib/python3.10/dist-packages/pandas/io/parsers/readers.py", line 1661, in _make_engine
self.handles = get_handle(
File "/usr/local/lib/python3.10/dist-packages/pandas/io/common.py", line 859, in get_handle
handle = open(
FileNotFoundError: [Errno 2] No such file or directory: 'images/train_labels.csv'
Traceback (most recent call last):
File "/content/create_tfrecord.py", line 120, in
tf.app.run()
File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/platform/app.py", line 36, in run
_run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef)
File "/usr/local/lib/python3.10/dist-packages/absl/app.py", line 308, in run
_run_main(main, args)
File "/usr/local/lib/python3.10/dist-packages/absl/app.py", line 254, in _run_main
sys.exit(main(argv))
File "/content/create_tfrecord.py", line 93, in main
examples = pd.read_csv(FLAGS.csv_input)
File "/usr/local/lib/python3.10/dist-packages/pandas/io/parsers/readers.py", line 912, in read_csv
return _read(filepath_or_buffer, kwds)
File "/usr/local/lib/python3.10/dist-packages/pandas/io/parsers/readers.py", line 577, in _read
parser = TextFileReader(filepath_or_buffer, **kwds)
File "/usr/local/lib/python3.10/dist-packages/pandas/io/parsers/readers.py", line 1407, in init
self._engine = self._make_engine(f, self.engine)
File "/usr/local/lib/python3.10/dist-packages/pandas/io/parsers/readers.py", line 1661, in _make_engine
self.handles = get_handle(
File "/usr/local/lib/python3.10/dist-packages/pandas/io/common.py", line 859, in get_handle
handle = open(
FileNotFoundError: [Errno 2] No such file or directory: 'images/validation_labels.csv'

im having the same issue did you find the solution?

i have found the solution:

change the code of create_csv.py to this:

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'):
            try:
                filename = root.find('filename').text
                width = int(root.find('size')[0].text)
                height = int(root.find('size')[1].text)
                class_name = member[0].text
                bbox = member.find('bndbox')
                
                if bbox is not None:
                    xmin = int(bbox.find('xmin').text)
                    ymin = int(bbox.find('ymin').text)
                    xmax = int(bbox.find('xmax').text)
                    ymax = int(bbox.find('ymax').text)
                    
                    value = (filename, width, height, class_name, xmin, ymin, xmax, ymax)
                    xml_list.append(value)
                else:
                    print(f"No bounding box found in file: {xml_file}")
            except IndexError as e:
                print(f"IndexError: {e} in file: {xml_file}")
            except AttributeError as e:
                print(f"AttributeError: {e} in file: {xml_file}")

    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()

yes workss