Skip to content

Commit 25cc31d

Browse files
fix style and wrong point order (#2052)
1 parent 26323da commit 25cc31d

12 files changed

Lines changed: 118 additions & 30 deletions

File tree

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ style:
1313
test:
1414
coverage run -m pytest tests/common/ -rs
1515
coverage run -m pytest tests/pytorch/ -rs
16+
coverage report --fail-under=80 --show-missing
1617

1718
test-common:
1819
coverage run -m pytest tests/common/ -rs

README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ As such, you can select the architecture used for [text detection](https://minde
2424
```python
2525
from doctr.models import ocr_predictor
2626

27-
model = ocr_predictor(det_arch='db_resnet50', reco_arch='crnn_vgg16_bn', pretrained=True)
27+
model = ocr_predictor(det_arch="db_resnet50", reco_arch="crnn_vgg16_bn", pretrained=True)
2828
```
2929

3030
### Reading files
@@ -33,6 +33,7 @@ Documents can be interpreted from PDF or images:
3333

3434
```python
3535
from doctr.io import DocumentFile
36+
3637
# PDF
3738
pdf_doc = DocumentFile.from_pdf("path/to/your/doc.pdf")
3839
# Image
@@ -87,7 +88,9 @@ Or even rebuild the original document from its predictions:
8788
import matplotlib.pyplot as plt
8889

8990
synthetic_pages = result.synthesize()
90-
plt.imshow(synthetic_pages[0]); plt.axis('off'); plt.show()
91+
plt.imshow(synthetic_pages[0])
92+
plt.axis("off")
93+
plt.show()
9194
```
9295

9396
![Synthesis sample](https://github.com/mindee/doctr/raw/main/docs/images/synthesized_sample.png)
@@ -112,7 +115,7 @@ from doctr.io import DocumentFile
112115
from doctr.models import kie_predictor
113116

114117
# Model
115-
model = kie_predictor(det_arch='db_resnet50', reco_arch='crnn_vgg16_bn', pretrained=True)
118+
model = kie_predictor(det_arch="db_resnet50", reco_arch="crnn_vgg16_bn", pretrained=True)
116119
# PDF
117120
doc = DocumentFile.from_pdf("path/to/your/doc.pdf")
118121
# Analyze
@@ -313,7 +316,7 @@ import requests
313316

314317
params = {"det_arch": "db_resnet50", "reco_arch": "crnn_vgg16_bn"}
315318

316-
with open('/path/to/your/doc.jpg', 'rb') as f:
319+
with open("/path/to/your/doc.jpg", "rb") as f:
317320
files = [ # application/pdf, image/jpeg, image/png supported
318321
("files", ("doc.jpg", f.read(), "image/jpeg")),
319322
]

api/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import requests
3939
headers = {"accept": "application/json"}
4040
params = {"det_arch": "db_resnet50"}
4141

42-
with open('/path/to/your/img.jpg', 'rb') as f:
42+
with open("/path/to/your/img.jpg", "rb") as f:
4343
files = [ # application/pdf, image/jpeg, image/png supported
4444
("files", ("117319856-fc35bf00-ae8b-11eb-9b51-ca5aba673466.jpg", f.read(), "image/jpeg")),
4545
]
@@ -83,7 +83,7 @@ import requests
8383
headers = {"accept": "application/json"}
8484
params = {"reco_arch": "crnn_vgg16_bn"}
8585

86-
with open('/path/to/your/img.jpg', 'rb') as f:
86+
with open("/path/to/your/img.jpg", "rb") as f:
8787
files = [ # application/pdf, image/jpeg, image/png supported
8888
("files", ("117133599-c073fa00-ada4-11eb-831b-412de4d28341.jpeg", f.read(), "image/jpeg")),
8989
]
@@ -115,7 +115,7 @@ import requests
115115
headers = {"accept": "application/json"}
116116
params = {"det_arch": "db_resnet50", "reco_arch": "crnn_vgg16_bn"}
117117

118-
with open('/path/to/your/img.jpg', 'rb') as f:
118+
with open("/path/to/your/img.jpg", "rb") as f:
119119
files = [ # application/pdf, image/jpeg, image/png supported
120120
("files", ("117319856-fc35bf00-ae8b-11eb-9b51-ca5aba673466.jpg", f.read(), "image/jpeg")),
121121
]

api/tests/conftest.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,24 +45,24 @@ def mock_detection_response():
4545
"name": "117319856-fc35bf00-ae8b-11eb-9b51-ca5aba673466.jpg",
4646
"geometries": [
4747
[
48-
0.8203927977629988,
49-
0.2021484375,
5048
0.8203927977629988,
5149
0.181640625,
5250
0.906015010958283,
5351
0.181640625,
5452
0.906015010958283,
5553
0.2021484375,
54+
0.8203927977629988,
55+
0.2021484375,
5656
],
5757
[
58-
0.7467381290758103,
59-
0.20086261630058289,
6058
0.7482568619833604,
6159
0.17938309907913208,
6260
0.8208542842026056,
6361
0.1819499135017395,
6462
0.8193355512950555,
6563
0.2034294307231903,
64+
0.7467381290758103,
65+
0.20086261630058289,
6666
],
6767
],
6868
},
@@ -208,26 +208,26 @@ def mock_ocr_response():
208208
"blocks": [
209209
{
210210
"geometry": [
211-
0.9052250981330872,
212-
0.20474359393119812,
213211
0.7460642457008362,
214212
0.2017778754234314,
215213
0.7464945912361145,
216214
0.17868199944496155,
217215
0.9056554436683655,
218216
0.18164771795272827,
217+
0.9052250981330872,
218+
0.20474359393119812,
219219
],
220220
"lines": [
221221
{
222222
"geometry": [
223-
0.9052250981330872,
224-
0.20474359393119812,
225223
0.7460642457008362,
226224
0.2017778754234314,
227225
0.7464945912361145,
228226
0.17868199944496155,
229227
0.9056554436683655,
230228
0.18164771795272827,
229+
0.9052250981330872,
230+
0.20474359393119812,
231231
],
232232
"objectness_score": 0.54,
233233
"words": [

doctr/datasets/generator/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def __init__(
6666
) -> None:
6767
self.vocab = vocab
6868
self._num_samples = num_samples
69-
self.font_family = font_family if isinstance(font_family, list) else [font_family] # type: ignore[list-item]
69+
self.font_family = font_family if isinstance(font_family, list) else [font_family]
7070
# Validate fonts
7171
if isinstance(font_family, list):
7272
for font in self.font_family:
@@ -116,7 +116,7 @@ def __init__(
116116
self.vocab = vocab
117117
self.wordlen_range = (min_chars, max_chars)
118118
self._num_samples = num_samples
119-
self.font_family = font_family if isinstance(font_family, list) else [font_family] # type: ignore[list-item]
119+
self.font_family = font_family if isinstance(font_family, list) else [font_family]
120120
# Validate fonts
121121
if isinstance(font_family, list):
122122
for font in self.font_family:

doctr/models/builder.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -317,10 +317,8 @@ def __call__(
317317
) != len(crop_orientations) != len(objectness_scores):
318318
raise ValueError("All arguments are expected to be lists of the same size")
319319

320-
_orientations = (
321-
orientations if isinstance(orientations, list) else [None] * len(boxes) # type: ignore[list-item]
322-
)
323-
_languages = languages if isinstance(languages, list) else [None] * len(boxes) # type: ignore[list-item]
320+
_orientations = orientations if isinstance(orientations, list) else [None] * len(boxes)
321+
_languages = languages if isinstance(languages, list) else [None] * len(boxes)
324322
if self.export_as_straight_boxes and len(boxes) > 0:
325323
# If boxes are already straight OK, else fit a bounding rect
326324
if boxes[0].ndim == 3:
@@ -402,10 +400,8 @@ def __call__( # type: ignore[override]
402400
page_shapes
403401
) != len(crop_orientations) != len(objectness_scores):
404402
raise ValueError("All arguments are expected to be lists of the same size")
405-
_orientations = (
406-
orientations if isinstance(orientations, list) else [None] * len(boxes) # type: ignore[list-item]
407-
)
408-
_languages = languages if isinstance(languages, list) else [None] * len(boxes) # type: ignore[list-item]
403+
_orientations = orientations if isinstance(orientations, list) else [None] * len(boxes)
404+
_languages = languages if isinstance(languages, list) else [None] * len(boxes)
409405
if self.export_as_straight_boxes and len(boxes) > 0:
410406
# If boxes are already straight OK, else fit a bounding rect
411407
if next(iter(boxes[0].values())).ndim == 3:

doctr/models/detection/differentiable_binarization/base.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import pyclipper
1212
from shapely.geometry import Polygon
1313

14+
from doctr.utils import order_points
15+
1416
from ..core import DetectionPostProcessor
1517

1618
__all__ = ["DBPostProcessor"]
@@ -80,7 +82,7 @@ def polygon_to_box(
8082
return (
8183
cv2.boundingRect(expanded_points) # type: ignore[return-value]
8284
if self.assume_straight_pages
83-
else np.roll(cv2.boxPoints(cv2.minAreaRect(expanded_points)), -1, axis=0)
85+
else order_points(cv2.boxPoints(cv2.minAreaRect(expanded_points)))
8486
)
8587

8688
def bitmap_to_boxes(

doctr/models/detection/fast/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from shapely.geometry import Polygon
1313

1414
from doctr.models.core import BaseModel
15+
from doctr.utils import order_points
1516

1617
from ..core import DetectionPostProcessor
1718

@@ -78,7 +79,7 @@ def polygon_to_box(
7879
return (
7980
cv2.boundingRect(expanded_points) # type: ignore[return-value]
8081
if self.assume_straight_pages
81-
else np.roll(cv2.boxPoints(cv2.minAreaRect(expanded_points)), -1, axis=0)
82+
else order_points(cv2.boxPoints(cv2.minAreaRect(expanded_points)))
8283
)
8384

8485
def bitmap_to_boxes(

doctr/models/detection/linknet/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from shapely.geometry import Polygon
1313

1414
from doctr.models.core import BaseModel
15+
from doctr.utils import order_points
1516

1617
from ..core import DetectionPostProcessor
1718

@@ -78,7 +79,7 @@ def polygon_to_box(
7879
return (
7980
cv2.boundingRect(expanded_points) # type: ignore[return-value]
8081
if self.assume_straight_pages
81-
else np.roll(cv2.boxPoints(cv2.minAreaRect(expanded_points)), -1, axis=0)
82+
else order_points(cv2.boxPoints(cv2.minAreaRect(expanded_points)))
8283
)
8384

8485
def bitmap_to_boxes(

doctr/models/detection/zoo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ def _predictor(arch: Any, pretrained: bool, assume_straight_pages: bool = True,
5050
raise ValueError(f"unknown architecture: {type(arch)}")
5151

5252
_model = arch
53-
_model.assume_straight_pages = assume_straight_pages
54-
_model.postprocessor.assume_straight_pages = assume_straight_pages
53+
_model.assume_straight_pages = assume_straight_pages # type: ignore[attr-defined]
54+
_model.postprocessor.assume_straight_pages = assume_straight_pages # type: ignore[attr-defined]
5555

5656
kwargs.pop("pretrained_backbone", None)
5757

0 commit comments

Comments
 (0)