diff --git a/get_json_file_YOLO.py b/get_json_file_YOLO.py new file mode 100644 index 0000000000000000000000000000000000000000..aa85ee545f0ff1aa5e459064804fa0668934f893 --- /dev/null +++ b/get_json_file_YOLO.py @@ -0,0 +1,40 @@ +# /!\ TO DO before : globox convert input_YOLO/labels/val/ output_../classifier/test_convert_labels/ --format yolo --save_fmt labelme --img_folder YOLO/images/val/ #path to images + +import os +import json +import labelme +import base64 +import pandas as pd + +mode = 'train' #or val +img_dir = str('../annot/YOLO/images/'+mode+'/') + +filename = 'test_convert_labels_train/' #path to .json +out_file = 'test_convert_labels_train_2/' #direction +img_path = '/nfs/NAS7/manip_stephane/annot/YOLO/images/train/' + +liste_file = os.listdir(filename) +liste_file = pd.DataFrame(liste_file, columns =['fn']) + +for i in range (len(liste_file)): + if liste_file.fn[i][0] == '.': + liste_file = liste_file.drop(i) + +liste_file = liste_file.reset_index() + +for i, row in liste_file.iterrows(): + if len(row.fn) > 30: + data = labelme.LabelFile.load_image_file(img_dir+row.fn[:-4]+'jpg') + image_data = base64.b64encode(data).decode('utf-8') + else: + continue + try : + len(data) + except TypeError: + continue + f = open(filename+row.fn,) + get_data = json.load(f) + get_data['imageData'] = image_data + get_data['imagePath'] = img_path+row.fn[:-4]+'jpg' + with open(out_file+row.fn, 'w') as f: + json.dump(get_data, f, indent=4)