Skip to content
Snippets Groups Projects
Commit abf73e60 authored by Stephane Chavin's avatar Stephane Chavin
Browse files

add convert json

parent 80c46bbb
Branches
No related tags found
No related merge requests found
# /!\ 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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment