mirror of
https://github.com/qurator-spk/eynollah.git
synced 2026-05-01 03:32:00 +02:00
.
This commit is contained in:
parent
5c6e075975
commit
511222704e
4 changed files with 53 additions and 43 deletions
|
|
@ -72,7 +72,7 @@ class Eynollah_ocr:
|
||||||
self.model_zoo.load_model('ocr', '')
|
self.model_zoo.load_model('ocr', '')
|
||||||
self.model_zoo.load_model('num_to_char')
|
self.model_zoo.load_model('num_to_char')
|
||||||
self.model_zoo.load_model('characters')
|
self.model_zoo.load_model('characters')
|
||||||
self.end_character = len(self.model_zoo.get('characters', list)) + 2
|
self.end_character = len(self.model_zoo.get('characters')) + 2
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device(self):
|
def device(self):
|
||||||
|
|
|
||||||
|
|
@ -197,9 +197,12 @@ class EynollahModelZoo:
|
||||||
return model
|
return model
|
||||||
|
|
||||||
def get(self, model_category: str) -> Predictor:
|
def get(self, model_category: str) -> Predictor:
|
||||||
if model_category not in self._loaded:
|
# if model_category not in self._loaded:
|
||||||
raise ValueError(f'Model "{model_category}" not previously loaded with "load_model(..)"')
|
# raise ValueError(f'Model "{model_category}" not previously loaded with "load_model(..)"')
|
||||||
return self._loaded[model_category]
|
if model_category in self._loaded:
|
||||||
|
return self._loaded[model_category]
|
||||||
|
else:
|
||||||
|
return self.load_model(model_category)
|
||||||
|
|
||||||
def _load_ocr_model(self, variant: str) -> AnyModel:
|
def _load_ocr_model(self, variant: str) -> AnyModel:
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -162,43 +162,50 @@
|
||||||
"version_range": "< v0.7.0"
|
"version_range": "< v0.7.0"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
|
||||||
},
|
|
||||||
"ocrd-eynollah-recognize": {
|
|
||||||
"executable": "ocrd-eynollah-recognize",
|
|
||||||
"categories": ["Text recognition and optimization"],
|
|
||||||
"steps": ["recognition/text-recognition"],
|
|
||||||
"input_file_grp_cardinality": 1,
|
|
||||||
"output_file_grp_cardinality": 1,
|
|
||||||
"parameters": {
|
|
||||||
"models": {
|
|
||||||
"type": "string",
|
|
||||||
"format": "uri",
|
|
||||||
"content-type": "text/directory",
|
|
||||||
"cacheable": true,
|
|
||||||
"description": "Directory containing the eynollah_models directory",
|
|
||||||
"required": true
|
|
||||||
},
|
|
||||||
"do_not_mask_with_textline_contour": {
|
|
||||||
"type": "boolean",
|
|
||||||
"description": "if this parameter set to true, cropped textline images will not be masked with textline contour.",
|
|
||||||
"default": false
|
|
||||||
},
|
|
||||||
"tr_ocr": {
|
|
||||||
"type": "boolean",
|
|
||||||
"description": "Whether to use (much more resource-intensive) transformer model",
|
|
||||||
"default": false
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"resources": [
|
"ocrd-eynollah-recognize": {
|
||||||
{
|
"executable": "ocrd-eynollah-recognize",
|
||||||
"url": "https://zenodo.org/records/17580627/files/models_ocr_v0_6_0.tar.gz?download=1",
|
"categories": ["Text recognition and optimization"],
|
||||||
"name": "models_ocr_v0_6_0",
|
"steps": ["recognition/text-recognition"],
|
||||||
"type": "archive",
|
"input_file_grp_cardinality": 1,
|
||||||
"size": 6119874002,
|
"output_file_grp_cardinality": 1,
|
||||||
"description": "Models for OCR",
|
"description": "Recognize text with eynollah (CNN/RNN or Transformer)",
|
||||||
"version_range": ">= v0.6.0"
|
"parameters": {
|
||||||
}
|
"models": {
|
||||||
]
|
"type": "string",
|
||||||
|
"format": "uri",
|
||||||
|
"content-type": "text/directory",
|
||||||
|
"cacheable": true,
|
||||||
|
"description": "Directory containing the eynollah_models directory",
|
||||||
|
"required": true
|
||||||
|
},
|
||||||
|
"do_not_mask_with_textline_contour": {
|
||||||
|
"type": "boolean",
|
||||||
|
"description": "if this parameter set to true, cropped textline images will not be masked with textline contour.",
|
||||||
|
"default": false
|
||||||
|
},
|
||||||
|
"tr_ocr": {
|
||||||
|
"type": "boolean",
|
||||||
|
"description": "Whether to use (much more resource-intensive) transformer model",
|
||||||
|
"default": false
|
||||||
|
},
|
||||||
|
"batch_size": {
|
||||||
|
"type": "number",
|
||||||
|
"format": "integer",
|
||||||
|
"description": "Batch size, leave as 0 for builtin default (2 for CNN/RNN, 2 for TrOCR)",
|
||||||
|
"default": 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"resources": [
|
||||||
|
{
|
||||||
|
"url": "https://zenodo.org/records/17580627/files/models_ocr_v0_6_0.tar.gz?download=1",
|
||||||
|
"name": "models_ocr_v0_6_0",
|
||||||
|
"type": "archive",
|
||||||
|
"size": 6119874002,
|
||||||
|
"description": "Models for OCR",
|
||||||
|
"version_range": ">= v0.6.0"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,8 +34,8 @@ class EynollahRecognizeProcessor(Processor):
|
||||||
model_zoo=model_zoo,
|
model_zoo=model_zoo,
|
||||||
tr_ocr=self.parameter['tr_ocr'],
|
tr_ocr=self.parameter['tr_ocr'],
|
||||||
do_not_mask_with_textline_contour=self.parameter['do_not_mask_with_textline_contour'],
|
do_not_mask_with_textline_contour=self.parameter['do_not_mask_with_textline_contour'],
|
||||||
batch_size=self.parameter['batch_size'],
|
batch_size=self.parameter['batch_size'] if self.parameter['batch_size'] >= 0 else 2 if self.parameter['tr_ocr'] else 8,
|
||||||
min_conf_value_of_textline_text=self.parameter['min_conf_value_of_textline_text'])
|
min_conf_value_of_textline_text=0)
|
||||||
|
|
||||||
# FIXME: This is just a proof-of-concept, very inefficient and non-conformant
|
# FIXME: This is just a proof-of-concept, very inefficient and non-conformant
|
||||||
# TODO: OCR writing should use PAGE API once result dataclass mechanism is settled,
|
# TODO: OCR writing should use PAGE API once result dataclass mechanism is settled,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue