Views
No views yet
https://github.com/nakasyou/capsolve-sppip install huggingface-hub onnxruntime pillow numpy1from huggingface_hub import hf_hub_download
2from PIL import Image
3import numpy as np
4import onnxruntime as ort
5
6REPO_ID = "nakasyou/capsolve-sp"
7CHARSET = "0123456789abcdefghijklmnopqrstuvwxyz"
8
9model_path = hf_hub_download(REPO_ID, "model.onnx")
10session = ort.InferenceSession(
11 model_path,
12 providers=["CPUExecutionProvider"],
13)
14
15with Image.open("captcha.png") as source:
16 image = source.convert("L")
17 if image.size != (175, 60):
18 raise ValueError("captcha image must be 175x60 pixels")
19 pixels = np.asarray(image, dtype=np.float32)
20
21# The model expects white background as 0 and dark ink as 1.
22input_tensor = ((255.0 - pixels) / 255.0)[None, None, :, :]
23logits = session.run(["logits"], {"image": input_tensor})[0]
24text = "".join(CHARSET[index] for index in logits[0].argmax(axis=-1))
25print(text)model.onnx to model-fp32.onnx.model.onnx: calibrated INT8 ONNX, recommended for fast CPU inferencemodel-fp32.onnx: FP32 ONNXmodel.safetensors: PyTorch architecture weightsconfig.json: architecture and preprocessing configurationmetadata.json: training and evaluation metadata0 and ink is 10123456789abcdefghijklmnopqrstuvwxyz| Validation metric | Result |
|---|---|
| Character accuracy | 96.94% |
| Exact five-character accuracy | 87.00% |
0.png images:| Runtime model | Exact accuracy |
|---|---|
| FP32 ONNX | 85.047% (12,189 / 14,332) |
| INT8 ONNX | 85.033% (12,187 / 14,332) |
LICENSE.