Skip to content

Commit e41d9ce

Browse files
committed
Update docstrings
1 parent 4e50849 commit e41d9ce

File tree

9 files changed

+52
-16
lines changed

9 files changed

+52
-16
lines changed

kraken/align.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
align
1919
~~~~~
2020
21-
A character alignment module using a network output lattice and ground truth to
22-
accuractely determine grapheme locations in input data.
21+
Legacy API for forced alignment using the network output lattice. New
22+
applications should use the ForcedAlignmentTaskModel from kraken.tasks.
2323
"""
2424
import logging
2525
import warnings

kraken/binarization.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
kraken.binarization
1818
~~~~~~~~~~~~~~~~~~~
1919
20-
An adaptive binarization algorithm.
20+
An adaptive binarization algorithm. This code is legacy and only remains for
21+
historical reasons. Binarization is no longer necessary for most workflows.
2122
"""
2223
import logging
2324
import warnings

kraken/blla.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
kraken.blla
1717
~~~~~~~~~~~
1818
19-
Trainable layout analysis tools for kraken for line and region detection. The
20-
line recognizer uses the baseline paradigm.
19+
Legacy API for inference using the trainable baseline and region detection
20+
segmenter. New code should use the SegmentationTaskModel from kraken.tasks.
2121
"""
2222
import PIL
2323
import uuid

kraken/models/_coreml.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"""
2-
kraken.models.loaders
2+
kraken.models._coreml
33
~~~~~~~~~~~~~~~~~~~~~~~~~
44
5-
Implementation for model metadata and weight loading from various formats.
5+
Implementation for weight loading from a CoreML NeuralNetwork object.
66
"""
77
import torch
88

kraken/models/loaders.py

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,17 @@ def load_models(path: Union[str, 'PathLike'], tasks: Optional[Sequence[_T_tasks]
4242
def load_safetensors(path: Union[str, PathLike], tasks: Optional[Sequence[_T_tasks]] = None) -> list[BaseModel]:
4343
"""
4444
Loads one or more models in safetensors format and returns them.
45+
46+
Args:
47+
path: Path to the safetensors file.
48+
tasks: Filter for model types to load from file.
49+
50+
Returns:
51+
A list of models.
52+
53+
Raises:
54+
ValueError: When model metadata is incomplete or the safetensors file
55+
is invalid.
4556
"""
4657
from torch import nn
4758
from safetensors import safe_open, SafetensorError
@@ -74,7 +85,18 @@ def load_safetensors(path: Union[str, PathLike], tasks: Optional[Sequence[_T_tas
7485

7586
def load_coreml(path: Union[str, PathLike], tasks: Optional[Sequence[_T_tasks]] = None) -> list[BaseModel]:
7687
"""
77-
Loads a model in coreml format.
88+
Loads a model in CoreML format.
89+
90+
Args:
91+
path: Path to the coreml file.
92+
tasks: Filter for model types to load from file.
93+
94+
Returns:
95+
A list of models.
96+
97+
Raises:
98+
ValueError: When model metadata is incomplete or the coreml file
99+
is invalid.
78100
"""
79101
root_logger = logging.getLogger()
80102
level = root_logger.getEffectiveLevel()
@@ -83,6 +105,8 @@ def load_coreml(path: Union[str, PathLike], tasks: Optional[Sequence[_T_tasks]]
83105
root_logger.setLevel(level)
84106
from google.protobuf.message import DecodeError
85107

108+
models = []
109+
86110
if isinstance(path, PathLike):
87111
path = path.as_posix()
88112
try:
@@ -111,12 +135,14 @@ def load_coreml(path: Union[str, PathLike], tasks: Optional[Sequence[_T_tasks]]
111135
weights.update(cml_parser(spec))
112136

113137
model.load_state_dict(weights)
138+
models.append(model)
114139

115140
# construct additional models if auxiliary layers are defined.
116141

117-
# if 'aux_layers' in mlmodel.user_defined_metadata:
118-
# logger.info('Deserializing auxiliary layers.')
142+
if 'aux_layers' in mlmodel.user_defined_metadata:
143+
logger.info('Deserializing auxiliary layers.')
144+
145+
nn.aux_layers = {k: cls(v).nn.get_submodule(k) for k, v in json.loads(mlmodel.user_defined_metadata['aux_layers']).items()}
119146

120-
# nn.aux_layers = {k: cls(v).nn.get_submodule(k) for k, v in json.loads(mlmodel.user_defined_metadata['aux_layers']).items()}
147+
return models
121148

122-
return [model]

kraken/pageseg.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
kraken.pageseg
1818
~~~~~~~~~~~~~~
1919
20-
Layout analysis methods.
20+
The legacy bounding box segmentation method using conventional image processing
21+
techniques.
2122
"""
2223
import logging
2324
import uuid

kraken/rpred.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
kraken.rpred
1717
~~~~~~~~~~~~
1818
19-
Generators for recognition on lines images.
19+
Legacy line text recognition API. New code should use the RecognitionTaskModel
20+
from kraken.tasks which is more versatile and offers higher performance.
2021
"""
2122
import logging
2223
import warnings

kraken/serialization.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
1212
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
1313
# or implied. See the License for the specific language governing
1414
# permissions and limitations under the License.
15+
"""
16+
kraken.serialization
17+
~~~~~~~~~~~~~~~~~~~~
18+
19+
A serializer using Jinja2 templates to write segmentation and recognition
20+
results.
21+
"""
1522
import datetime
1623
import importlib.metadata
1724
import logging

kraken/tasks/segmentation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
kraken.lib.tasks.segmentation
33
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
44
5-
Wrappers around models for specific tasks.
5+
A wrapper around models for layout analysis and reading order determination.
66
"""
77
import torch
88
import shapely.geometry as geom
@@ -28,7 +28,7 @@
2828
logger = logging.getLogger(__name__)
2929

3030

31-
class SegmentationTaskModel:
31+
class SegmentationTaskModel(nn.Module):
3232
"""
3333
A wrapper class collecting one or more models that perform segmentation.
3434

0 commit comments

Comments
 (0)