I am using imitation learning to teach a car how to drive in Gazebo. I am using an image from the camera feed on the car as the data, and the respective velocity command for that frame as its label.
I saved all this data from a python script, into a text file, and it is formatted as "[[image]], dtype=uint8), ['velcmd1', ... 'velcmd6'] , with lots more entries that follow in same format as the first, as seen below.
"[[0, 0, 0, ..., 0, 0, 0], [0, 0, 0, ..., 0, 0, 0], ..., [0, 0, 0, ..., 0, 0, 0]], dtype=uint8), ['0.295245', '0.0', '0.0', '0.0', '0.0', '0.0']]", "[[0, 0, 0, ..., 0, 0, 0],
I need to convert this out of string formats and into two respective data types, one as an array that represents the image, and the other as a list that is the label. I have been able to separate the two by doing some ugly string.split() and string.replace(), and I have been able to get the label into the format, with its type being printed below:
[0.295245, 0.0, 0.0, 0.0, 0.0, 0.0]
<class 'list'>
I did this by evaluating the string of the label with ast.literal_eval().
For the image, I am able to get it into the format:
[[0, 0, 0, ..., 0, 0, 0], [0, 0, 0, ..., 0, 0, 0], [0, 0, 0, ..., 0, 0, 0], ..., [0, 0, 0, ..., 0, 0, 0], [0, 0, 0, ..., 0, 0, 0], [0, 0, 0, ..., 0, 0, 0]]
<class 'str'>
However, it is still a string, and ast.literal_eval() raises a Malformed String ValueError. I tried both of the last solutions here Malformed String ValueError ast.literal_eval() with String representation of Tuple
I instead tried to manually create an array then append the values to this array, which gives
['0, 0, 0, ..., 0, 0, 0', '0, 0, 0, ..., 0, 0, 0', '0, 0, 0, ..., 0, 0, 0', '..., 0, 0, 0, ..., 0, 0, 0', '0, 0, 0, ..., 0, 0, 0', '0, 0, 0, ..., 0, 0, 0']
<class 'list'>
However, now the individual entries are strings, and not arrays themselves.
When I have trained NN's in the past, the image data has been in the form:
[[ 32 31 30 ... 100 101 103]
[ 30 30 30 ... 100 101 103]
[ 30 30 31 ... 101 101 102]
...
[ 34 34 32 ... 87 87 87]
[ 30 30 29 ... 100 100 98]
[ 30 29 30 ... 100 99 100]]
<class 'numpy.ndarray'>
How can I convert that original string of the image from the text file into this final form?
Note: Training data is not all 0's (black), it is just binarized, so entries shown are black.