Tensorflow Training Data load error: could not convert string to float:

Hello,

I am trying to create my own custom dataset for the training of the model efficientdet_lite3, but when I run this code (The data csv file has the same format as the one specified on this link TensorFlow Lite Model Maker를 사용한 객체 감지):

train_data, validation_data, test_data = object_detector.DataLoader.from_csv(‘data.csv’)

The error that i get from the above code:

Traceback (most recent call last):
File “”, line 1, in
File “/Applications/PyCharm CE.app/Contents/plugins/python-ce/helpers/pydev/_pydev_bundle/pydev_umd.py”, line 197, in runfile
pydev_imports.execfile(filename, global_vars, local_vars) # execute the script
File “/Applications/PyCharm CE.app/Contents/plugins/python-ce/helpers/pydev/_pydev_imps/_pydev_execfile.py”, line 18, in execfile
exec(compile(contents+"\n", file, ‘exec’), glob, loc)
File “/Users/maryam/PycharmProjects/sp/newmodel.py”, line 23, in
train_data, validation_data, test_data = object_detector.DataLoader.from_csv(‘data.csv’)
File “/Users/maryam/PycharmProjects/sp/venv/lib/python3.8/site-packages/tensorflow_examples/lite/model_maker/core/data_util/object_detector_dataloader.py”, line 292, in from_csv
cache_writer.write_files(cache_files, csv_lines=csv_lines)
File “/Users/maryam/PycharmProjects/sp/venv/lib/python3.8/site-packages/tensorflow_examples/lite/model_maker/core/data_util/object_detector_dataloader_util.py”, line 247, in write_files
for idx, xml_dict in enumerate(self._get_xml_dict(*args, **kwargs)):
File “/Users/maryam/PycharmProjects/sp/venv/lib/python3.8/site-packages/tensorflow_examples/lite/model_maker/core/data_util/object_detector_dataloader_util.py”, line 380, in _get_xml_dict
xml_dict = _get_xml_dict_from_csv_lines(self.images_dir, image_filename,
File “/Users/maryam/PycharmProjects/sp/venv/lib/python3.8/site-packages/tensorflow_examples/lite/model_maker/core/data_util/object_detector_dataloader_util.py”, line 337, in _get_xml_dict_from_csv_lines
xmin, ymin = float(line[3]) * width, float(line[4]) * height
ValueError: could not convert string to float: ‘’

Is there a possible answer for this problem?

Thank you

Hi Marz,

By the error ("ValueError: could not convert string to float: ") maybe the column has some values with the wrong format (maybe on the column 3 and 4). Maybe the float separator is not the expected one.

hope it helps

The third and fourth element on the line are the x and y min values of the images that need to be trained and i made sure that they are on float data type and still i get the same error.

I understand,

It’s a little bit hard to know what is wrong, but maybe the lib is trying to load an empty string
if you try a = float("") it returns exactly the same error.
If could be an extra “\n” in the end or some empty line in the file.
Sorry for the vague answer but it might need some debugging to find the the value that can’t be converted.

Maybe because the test data has no numbers and this is considered almost float("").
I dont know how to fix it.

yes, that could be an option.
Can’t you split your train data to get a something on the test split?
At least to unblock you and get the full process going.