Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Bentoml BentoML Framework EasyOCR

From Leeroopedia
Knowledge Sources
Domains ML Framework, OCR, Model Serialization
Last Updated 2026-02-13 15:00 GMT

Overview

Provides the BentoML framework integration for EasyOCR, enabling saving, loading, and serving EasyOCR Reader models through the BentoML model store.

Description

This module implements the standard BentoML framework adapter pattern for EasyOCR. It exposes four public functions: get(), load_model(), save_model(), and get_runnable().

save_model() serializes an easyocr.Reader instance using cloudpickle and stores it in the BentoML model store. Default model signatures include non-batchable methods (detect, readtext, readtextlang, recognize) and a batchable method (readtext_batched). The model context records the easyocr framework version.

load_model() retrieves the model from the store by tag and deserializes it with cloudpickle.load(), returning an easyocr.Reader instance.

get() retrieves the BentoML Model metadata object for a given tag, validating that it was saved with the EasyOCR module.

get_runnable() creates a dynamic EasyOCRRunnable class (subclass of bentoml.legacy.Runnable) that loads the model on initialization and maps each signature method to a runnable method with the appropriate batchable and batch_dim settings. The runnable supports both GPU and CPU resources.

Usage

Use this module to save pre-trained EasyOCR reader models to the BentoML model store and serve them via BentoML services. Access via bentoml.easyocr.

Code Reference

Source Location

Signature

def get(tag_like: str | Tag) -> Model: ...

def load_model(bento_model: str | Tag | Model) -> easyocr.Reader: ...

def save_model(
    name: Tag | str,
    reader: easyocr.Reader,
    *,
    signatures: ModelSignaturesType | None = None,
    labels: dict[str, str] | None = None,
    custom_objects: dict[str, t.Any] | None = None,
    external_modules: t.List[ModuleType] | None = None,
    metadata: dict[str, t.Any] | None = None,
) -> bentoml.Model: ...

def get_runnable(bento_model: bentoml.Model) -> type[bentoml.legacy.Runnable]: ...

Import

import bentoml

# Via the public API
model = bentoml.easyocr.save_model("reader", reader)
reader = bentoml.easyocr.load_model("reader:latest")

# Direct import
from bentoml._internal.frameworks.easyocr import save_model, load_model, get, get_runnable

I/O Contract

Inputs

Name Type Required Description
name Tag or str Yes (save_model) Name or tag for the model in the store
reader easyocr.Reader Yes (save_model) The EasyOCR Reader instance to save
tag_like str or Tag Yes (get) Tag to retrieve from the model store
bento_model str, Tag, or Model Yes (load_model) Model identifier or object to load
signatures ModelSignaturesType or None No Method signatures; defaults to detect, readtext, readtextlang, recognize (non-batchable) and readtext_batched (batchable)
labels dict[str, str] or None No User-defined labels for model management
custom_objects dict[str, Any] or None No Additional objects to save with the model
external_modules List[ModuleType] or None No Additional Python modules to bundle
metadata dict[str, Any] or None No Custom metadata for the model

Outputs

Name Type Description
bentoml.Model (save_model) bentoml.Model The saved model reference in the BentoML store
easyocr.Reader (load_model) easyocr.Reader The deserialized EasyOCR reader instance
Model (get) Model BentoML Model metadata object
EasyOCRRunnable (get_runnable) type[Runnable] A Runnable class for serving the model

Usage Examples

import bentoml
import easyocr

# Create and save an EasyOCR reader
reader = easyocr.Reader(['en'])
bento_model = bentoml.easyocr.save_model('en_reader', reader)
print(f"Saved: {bento_model.tag}")

# Load the model back
loaded_reader = bentoml.easyocr.load_model('en_reader:latest')
results = loaded_reader.readtext('image.png')

# Retrieve model metadata
model = bentoml.easyocr.get('en_reader:latest')
print(model.info.signatures)

# Create a runnable for serving
runnable_cls = bentoml.easyocr.get_runnable(model)

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment