INNER CODE UNIT · Python

main

witchan/ios-mcp · scripts/prepare_paddleocr.py:18

def main():
    for name, digest in EXPECTED.items():
        assert hashlib.sha256((MODELS / name).read_bytes()).hexdigest() == digest, name
    # Paddle CTCLabelDecode: blank at zero, configured characters, then an ASCII space.
    characters = yaml.safe_load((MODELS / 'rec.yml').read_text())['PostProcess']['character_dict']
    dictionary = ['', *characters, ' ']
    for name in ('det', 'rec'):
        model = onnx.load(str(MODELS / (name + '.onnx')))
        onnx.checker.check_model(model)
        print(name, 'IR', model.ir_version, 'opset', [(i.domain, i.version) for i in model.opset_import])
        print('inputs', model.graph.input, 'outputs', model.graph.output)
        if name == 'rec':
            assert model.graph.output[0].type.tensor_type.shape.dim[-1].dim_value == len(dictionary)
    (MODELS / 'dictionary.json').write_text(json.dumps(dictionary, ensure_ascii=False) + '\n')
    hashes = {p.name: hashlib.sha256(p.read_bytes()).hexdigest()
              for p in sorted(MODELS.iterdir()) if p.name != 'sha256.json'}
    (MODELS / 'sha256.json').write_text(json.dumps(hashes, indent=2) + '\n')
    print('CTC classes:', len(dictionary))

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…