shengtao96 / CentripetalText

29 stars 6 forks source link

training with custom dataset #9

Open yazansayed opened 2 years ago

yazansayed commented 2 years ago

I tried to modify the code at ./dataset/ct/ct_tt.py to work with a custom dataset. the dataset stores the ground truth polygons as a json file for each image. sample json:

[
   [0, 560, 0, 639, 639, 639, 639, 560, 0, 560],
   [424, 357, 420, 359, 405, 361, 401, 363, 391, 364, 354, 373, 294, 381,....]
]

here's the get_ann function

def get_ann(img, gt_path):
    h, w = img.shape[0:2]
    bboxes = []
    words = []
    with open(gt_path,'r') as f:
     conts = [np.int0(c).reshape(-1,2) for c in json.load(f)]
    for cont in conts:
      numpoints = cont.shape[0]
      c= cont.reshape(-1) / ([w * 1.0, h * 1.0] * numpoints)
      bboxes.append(c)
      words.append('###')
    return bboxes, words

also modified the init function of the CT_TT class to get the new img_paths and gt_paths. and didn't modify anything else. but with training, the loss doesn't decrease below 0.9 !