r"""Construct a GeoLayoutLM processor. Args: max_seq_length: max length for token max_block_num: max number of text lines (blocks or segments) img_processor: type of ImageProcessor. tokenizer: to tokenize strings. use_roberta_tokenizer: Whether the tokeni
| 441 | |
| 442 | |
| 443 | class Processor(object): |
| 444 | r"""Construct a GeoLayoutLM processor. |
| 445 | |
| 446 | Args: |
| 447 | max_seq_length: max length for token |
| 448 | max_block_num: max number of text lines (blocks or segments) |
| 449 | img_processor: type of ImageProcessor. |
| 450 | tokenizer: to tokenize strings. |
| 451 | use_roberta_tokenizer: Whether the tokenizer is originated from RoBerta tokenizer |
| 452 | (True by default). |
| 453 | ocr_utils: a tool to preprocess ocr_infos. |
| 454 | width: default width. It can be used only when all the images are of the same shape. |
| 455 | height: default height. It can be used only when all the images are of the same shape. |
| 456 | |
| 457 | In `serialize_from_tokens`, the 3 sequences (i.e., `input_ids`, `bboxes_line`, `bboxes_word`) |
| 458 | must not contain special tokens like [CLS] or [SEP]. |
| 459 | The boxes in `bboxes_line` and `bboxes_word` can be presented by either 2 points or 4 points. |
| 460 | The value in boxes should keep original. |
| 461 | Here is an example of the 3 arguments: |
| 462 | ``` |
| 463 | input_ids -> |
| 464 | [[6, 2391, 6, 31833, 6, 10132, 6, 2283, 6, 17730, 6, 2698, 152]] |
| 465 | bboxes_line -> |
| 466 | [[[230, 1, 353, 38], [230, 1, 353, 38], [230, 1, 353, 38], [230, 1, 353, 38], |
| 467 | [230, 1, 353, 38], [230, 1, 353, 38], [230, 1, 353, 38], [230, 1, 353, 38], |
| 468 | [257, 155, 338, 191], [257, 155, 338, 191], [257, 155, 338, 191], [257, 155, 338, 191], |
| 469 | [257, 155, 338, 191]]] |
| 470 | bboxes_word -> |
| 471 | [[[231, 2, 267, 2, 267, 38, 231, 38], [231, 2, 267, 2, 267, 38, 231, 38], |
| 472 | [264, 7, 298, 7, 298, 36, 264, 36], [264, 7, 298, 7, 298, 36, 264, 36], |
| 473 | [293, 3, 329, 3, 329, 41, 293, 41], [293, 3, 329, 3, 329, 41, 293, 41], |
| 474 | [330, 4, 354, 4, 354, 39, 330, 39], [330, 4, 354, 4, 354, 39, 330, 39], |
| 475 | [258, 156, 289, 156, 289, 193, 258, 193], [258, 156, 289, 156, 289, 193, 258, 193], |
| 476 | [288, 158, 321, 158, 321, 192, 288, 192], [288, 158, 321, 158, 321, 192, 288, 192], |
| 477 | [321, 156, 336, 156, 336, 190, 321, 190]]] |
| 478 | ``` |
| 479 | |
| 480 | """ |
| 481 | |
| 482 | def __init__(self, |
| 483 | max_seq_length, |
| 484 | max_block_num, |
| 485 | img_processor: ImageProcessor, |
| 486 | tokenizer=None, |
| 487 | use_roberta_tokenizer: bool = True, |
| 488 | ocr_utils: OCRUtils = None, |
| 489 | width=768, |
| 490 | height=768, |
| 491 | **kwargs): |
| 492 | self.img_processor = img_processor |
| 493 | self.tokenizer = tokenizer |
| 494 | self.kwargs = kwargs |
| 495 | |
| 496 | self.serializer = TextLayoutSerializer( |
| 497 | max_seq_length, |
| 498 | max_block_num, |
| 499 | tokenizer, |
| 500 | width, |
no outgoing calls
no test coverage detected
searching dependent graphs…