This article introduces an efficient open-source project for Chinese optical character recognition (OCR), featuring a compact model size of just 17 megabytes. It's designed for scenarios where computational resources are limited, offering acceptable accuracy without requiring dedicated GPU hardware.
Optical Character Recognition has become integral to many applications, from automating data entry to enabling accessibility features. In China, OCR systems often need to handle complex scripts including vertical text layouts found in traditional documents or artistic compositions. This particular implementation focuses on optimizing performance for such use cases while keeping resource consumption minimal.
The solution presented here builds upon earlier architectures but introduces several optimizations:
- A lightweight backbone network based on PSENet for text detecsion
- An optimized CRNN-based recognizer suitable for constrained environments
- AngleNet for automatic determination of text orientation
These components work together to provide robust recognition capabilities across various text orientations and font styles, all within a remarkably small footprint.
Performance Evaluation
To evaluate its practical utility, we conducted tests using standard printed materials as well as more challenging samples like calligraphy. The results showed strong performance on machine-printed texts, though predictably less accurate on highly stylized fonts. For applications prioritizing speed and efficiency over perfect precision, this trade-off may be acceptable.
Deployment Using Docker
We chose Docker for deployment due to its portability and environment isolation benefits. Our setup included:
- Host OS: Ubuntu 18.04 LTS
- Python version: 3.6.9
- PyTorch (CPU-only): 1.5.0 nightly build
First, pull a preconfigured deep learning image that includes multiple frameworks:
# Pull from NetEase mirror for faster download in China
docker pull hub-mirror.c.163.com/ufoym/deepo
# Alternatively, use USTC mirror for academic networks
docker pull docker.mirrors.ustc.edu.cn/ufoym/deepo
Create and enter a new container instance:
docker run -it -p 6666:8080 \
-v ~/Desktop/input_data:/workspace \
--name light_ocr_container \
<image_id>
Inside the container, fetch the latest source code:
cd /workspace
git clone https://github.com/ouyanghuiyu/chineseocr_lite.git
cd chineseocr_lite
Install required dependencies using a domestic package index:
pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple -r requirements.txt
Start the web service:
python3 app.py 8080
Access the interface via browser at http://localhost:6666/ocr, since internal port 8080 maps to host port 6666.
Troubleshooting Common Issues
During testing, several system-level dependency issues arose. Here’s how they were resolved:
# Missing shared libraries error resolution
apt-get update
apt-get install apt-file
apt-file update
apt-file search libSM.so.6
apt-get install libsm6
# Additional missing X rendering components
apt-get install libxrender1
apt-get install python-qt4
After applying these fixes, the application started successfully. For detailed Docker configuration guidance, refer to external documentation covering containerized development environments.
Repository link: https://github.com/ouyanghuiyu/chineseocr_lite