Skip to content

Conversation

@fg-mindee
Copy link
Contributor

@fg-mindee fg-mindee commented May 21, 2021

This PR introduces the following modifications:

  • fixed a wrong normalization in the preprocessor introduced in refactor: Refactored PDF reader and preprocessor #25
  • refactored preprocessors with doctr.transforms for a cleaner interface
  • added symmetric pad option in transforms.Resize and updated the repr
  • updated predictors' repr
  • added an image existence check in the constructor of datasets
  • added a box flatness check in OCRDataset constructor
  • added a new pretrained DBNet checkpoint
  • updates the benchmark in the documentation
  • updated unittests accordingly
  • added recognition batch size as script argument for evaluation script
  • fixed transforms.RandomSaturation

Briefly, with the fix + refactor of the preprocessor, the repr of the predictor is now much more comprehensive:

from doctr.models import ocr_predictor
print(ocr_predictor(pretrained=True))

yields

OCRPredictor(
  (det_predictor): DetectionPredictor(
    (pre_processor): PreProcessor(
      (resize): Resize(output_size=(1024, 1024), method='bilinear')
      (normalize): Compose(
        (transforms): [
          LambdaTransformation(),
          Normalize(mean=[0.7979999780654907, 0.7850000262260437, 0.7720000147819519], std=[0.2639999985694885, 0.27489998936653137, 0.28700000047683716]),
        ]
      )
    )
    (model): DBNet(
      (feat_extractor): IntermediateLayerGetter()
      (fpn): FeaturePyramidNetwork(channels=128)
      (probability_head): <tensorflow.python.keras.engine.sequential.Sequential object at 0x7fbf100ee5e0>
      (threshold_head): <tensorflow.python.keras.engine.sequential.Sequential object at 0x7fbf101a0b20>
      (postprocessor): DBPostProcessor(box_thresh=0.1, max_candidates=1000)
    )
  )
  (reco_predictor): RecognitionPredictor(
    (pre_processor): PreProcessor(
      (resize): Resize(output_size=(32, 128), method='bilinear', preserve_aspect_ratio=True, symmetric_pad=False)
      (normalize): Compose(
        (transforms): [
          LambdaTransformation(),
          Normalize(mean=[0.5, 0.5, 0.5], std=[1.0, 1.0, 1.0]),
        ]
      )
    )
    (model): CRNN(
      (feat_extractor): <doctr.models.backbones.vgg.VGG object at 0x7fbf1035dfd0>
      (decoder): <tensorflow.python.keras.engine.sequential.Sequential object at 0x7fbf1003f730>
      (postprocessor): CTCPostProcessor(vocab_size=118)
    )
  )
  (doc_builder): DocumentBuilder(resolve_lines=False, resolve_blocks=False, paragraph_break=0.035)
)

Note that postprocessor are now printed and that you have the details of each preprocessor

Resolves #256

Any feedback is welcome!

@fg-mindee fg-mindee added topic: documentation Improvements or additions to documentation critical High priority module: models Related to doctr.models ext: scripts Related to scripts folder ext: tests Related to tests folder type: breaking change Introducing a breaking change module: datasets Related to doctr.datasets benchmark This issue reports a benchmark module: transforms Related to doctr.transforms labels May 21, 2021
@fg-mindee fg-mindee added this to the 0.2.1 milestone May 21, 2021
@fg-mindee fg-mindee self-assigned this May 21, 2021
@fg-mindee fg-mindee requested a review from charlesmindee May 21, 2021 12:21
Copy link
Collaborator

@charlesmindee charlesmindee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR ! Only a small comment on the results

charlesmindee
charlesmindee previously approved these changes May 21, 2021
Copy link
Collaborator

@charlesmindee charlesmindee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

Copy link
Collaborator

@charlesmindee charlesmindee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks

@codecov
Copy link

codecov bot commented May 21, 2021

Codecov Report

Merging #277 (0d6d4a3) into main (f959be6) will decrease coverage by 0.23%.
The diff coverage is 85.18%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #277      +/-   ##
==========================================
- Coverage   96.94%   96.71%   -0.24%     
==========================================
  Files          48       48              
  Lines        1966     1977      +11     
==========================================
+ Hits         1906     1912       +6     
- Misses         60       65       +5     
Flag Coverage Δ
unittests 96.71% <85.18%> (-0.24%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
doctr/datasets/cord.py 97.91% <50.00%> (-2.09%) ⬇️
doctr/datasets/detection.py 97.29% <50.00%> (-2.71%) ⬇️
doctr/datasets/funsd.py 97.56% <50.00%> (-2.44%) ⬇️
doctr/datasets/recognition.py 93.54% <50.00%> (-3.01%) ⬇️
doctr/datasets/sroie.py 97.91% <50.00%> (-2.09%) ⬇️
doctr/datasets/ocr.py 73.33% <72.72%> (-0.36%) ⬇️
doctr/models/detection/core.py 96.49% <100.00%> (-0.29%) ⬇️
...tr/models/detection/differentiable_binarization.py 93.99% <100.00%> (ø)
doctr/models/detection/linknet.py 96.58% <100.00%> (+0.02%) ⬆️
doctr/models/detection/zoo.py 100.00% <100.00%> (ø)
... and 7 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0248268...0d6d4a3. Read the comment docs.

@fg-mindee fg-mindee merged commit bcd6e0a into main May 21, 2021
@fg-mindee fg-mindee deleted the predictor-fix branch May 21, 2021 13:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

benchmark This issue reports a benchmark critical High priority ext: scripts Related to scripts folder ext: tests Related to tests folder module: datasets Related to doctr.datasets module: models Related to doctr.models module: transforms Related to doctr.transforms topic: documentation Improvements or additions to documentation type: breaking change Introducing a breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[transforms] Failing unittests for transformation

3 participants