Repository navigation
Expand file tree
/
Copy pathconvert.sh
More file actions
60 lines (50 loc) · 2.21 KB
/
Copy pathconvert.sh
File metadata and controls
60 lines (50 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env bash
#
# Copyright 2026 Akoos <https://akoos.eu>
# SPDX-License-Identifier: Apache-2.0
#
# Reproduces rec_latin.onnx from the official PaddleOCR release.
#
# It downloads latin_PP-OCRv5_mobile_rec (Paddle inference format), exports it to
# ONNX with paddle2onnx, downloads ppocrv5_latin_dict.txt, verifies the input and
# output shape, and checks every file against the SHA-256 the app pins.
#
# Runs on Linux with Python 3.10 to 3.12 (a container, WSL, or a plain machine).
# On a minimal image paddle needs the OpenMP runtime: `apt-get install -y libgomp1`.
#
set -euo pipefail
cd "$(dirname "$0")"
WORK="$(pwd)/build"
OUT="$(pwd)/../release-assets"
mkdir -p "$WORK" "$OUT"
REC_REPO="https://huggingface.co/PaddlePaddle/latin_PP-OCRv5_mobile_rec/resolve/main"
DICT_URL="https://raw.githubusercontent.com/PaddlePaddle/PaddleOCR/main/ppocr/utils/dict/ppocrv5_latin_dict.txt"
REC_SHA="995b0f5f28d2073896a78c03b5b863eae6af3744bafa0245b8522beea6994927"
DICT_SHA="ccbcc45730b3fbbd9050c5bc74db6a99067141ef1035e3d14889a84a6b9b1aff"
echo ">> python venv + dependencies"
python3 -m venv "$WORK/venv"
PY="$WORK/venv/bin/python"
"$PY" -m pip install -q --upgrade pip setuptools wheel
"$PY" -m pip install -q paddlepaddle paddle2onnx onnx
echo ">> download the upstream recognition model"
for f in inference.json inference.pdiparams inference.yml; do
curl -sL --fail "$REC_REPO/$f" -o "$WORK/$f"
done
echo ">> export to ONNX (opset 14, dynamic width preserved)"
"$WORK/venv/bin/paddle2onnx" \
--model_dir "$WORK" \
--model_filename inference.json \
--params_filename inference.pdiparams \
--save_file "$OUT/rec_latin.onnx" \
--opset_version 14
echo ">> download the dictionary"
curl -sL --fail "$DICT_URL" -o "$OUT/ppocrv5_latin_dict.txt"
echo ">> verify the ONNX shape (expects input [N,3,48,W], output [N,T,838])"
"$PY" verify.py "$OUT/rec_latin.onnx"
echo ">> verify SHA-256"
check() { echo "$2 $1" | sha256sum -c - ; }
check "$OUT/rec_latin.onnx" "$REC_SHA"
check "$OUT/ppocrv5_latin_dict.txt" "$DICT_SHA"
echo ">> done. rec_latin.onnx and ppocrv5_latin_dict.txt are in $OUT"
echo " det.onnx and cls.onnx are the language-agnostic PP-OCRv5 detection and"
echo " angle-classifier models and are shipped alongside them unchanged."