All Projects → thanhhau097 → chargrid2d

thanhhau097 / chargrid2d

Licence: other
No description, website, or topics provided.

Programming Languages

python
139335 projects - #7 most used programming language

Requirements

  • Python 3.6.5
  • Pytorch 1.2.0

To train model, first you need to run chargrid2d/dataloader_utils/generate_mask.py to generate data to train segmentation model from bounding box and text.

To use with any dataset, we need to do labeling corresponding class for each box in the image. The input data in json file should be a list of dictionary with keys: text, class, box.

[
    {
        "text": "abc",
        "class": "company_name",
        "box": [x, y, w, h]
    }
]

You can read the code in generate_masks.py file, which will call this function:

def __convert_data_sroie(self, label_json):
    std_out = []

    for item in label_json:
        for char in item['text']:
            if char not in self.__corpus__:
                self.__corpus__[char] = 1
            else:
                self.__corpus__[char] += 1

        std_out.append({
            'value': item['text'],
            'formal_key': item['class'],
            'key_type': 'value',
            'location': item['box']
        })

    return std_out

You could do the processing by using this (which was commented out in the main function) in generate_mask.py file:

mask_generator = MaskGenerator()
mask_generator.process(lbl_fol, img_fol, out_fol)
mask_generator.generate_mask('.')

Then you need to run train.py file to train the model.

python train.py

If you have any questions, please create an issue.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].