Paperspace / DataAugmentationForObjectDetection

Data Augmentation For Object Detection
https://blog.paperspace.com/data-augmentation-for-bounding-boxes/
MIT License
1.13k stars 318 forks source link

Convert txt to pkl #24

Open WellDL opened 4 years ago

WellDL commented 4 years ago

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

quangnmkma commented 1 year ago

I have the same the question :((

luigy-mach commented 1 year ago

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)