Paperspace/DataAugmentationForObjectDetection

Convert txt to pkl

WellDL opened this issue · 2 comments

I am not familiar to python, however this approach seems to be great for the type augmentations I need.
Since it is necessary to use pickle format, how can I change my txt file, which order is
classes x1 x2 y1 y2

to pickle format, which order needs to be the following?
x1 y1 x2 y2 classes

I have the same the question :((

In file quick-start.ipynb comment the next lines as follows:

# bboxes = pkl.load(open("messi_ann.pkl", "rb"))
# #inspect the bounding boxes
# print(bboxes)

And, add the next lines:

in_coor  = ['class','x1','y1','x2','y2'] # how in your file was sorted.
out_coor = ['x1','y1','x2','y2','class'] # how it was requested by algorithm.
filetxt  = 'yourfile.txt' # path of your file txt 
with open(filetxt) as f:
    contents = f.readlines()
    
data = list()
for i in contents:
    data.append([float(j) for j in i.split(',')])

data_arr  = np.asarray(data)
in_order  = {j:i for i,j in enumerate(in_coor)}
sort_in   = [in_order[k] for k in in_coor]
sort_out  = [in_order[k] for k in out_coor]

bboxes = data_arr[:,sort_out]
#inspect the bounding boxes

print(bboxes)