Pipeline and Stack
Pipeline
- class manuscript.Pipeline(detector=<default>, layout=<default>, recognizer=<default>, corrector=None, layout_after='detector', memory_policy='keep')[source]
Bases:
ModelCompositionHigh-level OCR pipeline with configurable stage ordering.
Default pipeline:
detector -> layout -> recognizer.correctoris optional and disabled by default.Initialize OCR pipeline.
- Parameters:
detector (object, optional) – Detector instance with
predict(image) -> Page. If omitted, defaultYOLO(weights="yolo26x_obb_text_g1")is used. Detector cannot be disabled.layout (object or None, optional) – Layout model instance with
predict(page, image=None) -> Page. If omitted, defaultSimpleSorting()is used. PassNoneto disable layout stage.recognizer (object or None, optional) – Recognizer instance with
predict(page, image=None, ...) -> Page. If omitted, defaultTRBA(weights="trba_lite_g2")is used. PassNoneto disable recognition stage.corrector (object or None, optional) – Corrector instance with
predict(page, image=None) -> Page. Default isNone(disabled).layout_after ({"detector", "recognizer", "corrector"}, optional) – Slot where layout stage is executed. Default is
"detector".memory_policy ({"keep", "sequential"}, optional) – Keep loaded model sessions by default. “sequential” releases sessions after each processor call, including on failure, and applies inside nested Stacks and ensembles. Participants require close(); nested parallel execution is incompatible. Shared models need external synchronization across pipelines and direct calls.
- get_text(page, format='plain', *, separators=None, separator_priorities=None)[source]
Delegate text serialization to Page.get_text.
- property last_timings: Dict[str, float]
Return elapsed seconds for the last predict call as a dictionary copy.
Keys: detector, layout, recognizer, corrector, load_image, visualization and total. Only executed stages are present. Stage times include tree validation/snapshots and lazy model initialization. Explicit image loading by Pipeline is recorded separately and subtracted from page-stage times. Loading performed inside a model remains part of that stage’s time. Total includes orchestration and optional visualization. On failure, completed stage timings remain available without a total entry.
Stack
- class manuscript.Stack(stages, *, parallel=False, memory_policy='keep')[source]
Bases:
ModelCompositionCombine processors in one Pipeline stage or run them directly.
- Parameters:
stages (iterable of processors) – Nonempty ordered collection implementing predict(image, …) or predict(page, image=None, …). Nested Stacks are supported.
parallel (bool, optional) – Run image detectors concurrently in threads if True; default is False. Results are merged in list order. Only detector-only Stacks support this mode; page processors require the preceding result.
memory_policy ({"keep", "sequential"}, optional) – Keep sessions loaded by default. “sequential” releases each processor’s sessions after its call, including on failure, and applies to nested compositions. Requires close() on every participant and disallows parallel=True. Participants must be exclusively owned or externally synchronized when shared with other callers.
Examples
>>> detector = Stack([block_detector, word_detector]) >>> page = detector.predict(image) >>> recognizer = Stack([recognizer_a, recognizer_b]) >>> page = recognizer.predict(page, image=image)
See also
manuscript.recognizers.MajorityVotingRecognizerVote by whole-string agreement.
manuscript.recognizers.MedoidRecognizerSelect by summed edit distance.
- predict(page=None, image=None, *, return_raw=False, return_masks=False, return_outputs=False, detector_result=None, **kwargs)[source]
Accept an image, a Page with optional image, or named inputs.
Return Page by default. Raw/mask/output flags return a dictionary with the final Page and detector results grouped by model. Page processors always run in Page mode. No prediction results are cached on the Stack.