Skip to content

Commit a421066

Browse files
committed
Add (Recognition|Segmentation)BaseModel classes
1 parent 3f0065a commit a421066

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

kraken/models/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from .base import BaseModel # NOQA
1+
from .base import * # NOQA
22
from .writers import * # NOQA
33
from .loaders import * # NOQA
44
from .utils import * # NOQA

kraken/models/base.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@
77
import logging
88

99
from abc import ABC, abstractmethod
10+
from collections.abc import Generator
1011
from typing import Union, Literal, NewType, TYPE_CHECKING
1112

12-
__all__ = ['BaseModel']
13+
__all__ = ['BaseModel',
14+
'RecognitionBaseModel',
15+
'SegmentationBaseModel']
1316

1417
if TYPE_CHECKING:
1518
from kraken.configs import Config
@@ -87,3 +90,24 @@ def prepare_for_inference(self, config: 'Config'):
8790
Prepares the model for inference.
8891
"""
8992
pass
93+
94+
95+
class SegmentationBaseModel(BaseModel):
96+
"""
97+
Base model metaclass for layout analysis models.
98+
"""
99+
@abstractmethod
100+
def predict(self, im: 'Image.Image') -> 'Segmentation':
101+
"""
102+
Computes a segmentation on an input image.
103+
"""
104+
pass
105+
106+
107+
class RecognitionBaseModel(BaseModel):
108+
"""
109+
Base model metaclass for text recognition models.
110+
"""
111+
@abstractmethod
112+
def predict(self, im: 'Image.Image', segmentation: 'Segmentation') -> Generator['ocr_record', None, None]:
113+
pass

0 commit comments

Comments
 (0)