Instructions to use ChrisMoe/handwriting-v3 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Keras
How to use ChrisMoe/handwriting-v3 with Keras:
# Available backend options are: "jax", "torch", "tensorflow". import os os.environ["KERAS_BACKEND"] = "jax" import keras model = keras.saving.load_model("hf://ChrisMoe/handwriting-v3") - Notebooks
- Google Colab
- Kaggle
Upload README.md with huggingface_hub
Browse files
README.md
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language: zh
|
| 3 |
+
tags:
|
| 4 |
+
- image-classification
|
| 5 |
+
- handwriting
|
| 6 |
+
- chinese
|
| 7 |
+
- keras
|
| 8 |
+
- tensorflow
|
| 9 |
+
- open-set-recognition
|
| 10 |
+
- resnet
|
| 11 |
+
license: mit
|
| 12 |
+
---
|
| 13 |
+
|
| 14 |
+
# Chinese Handwriting Recognition — HSK1 v3 (ResNet CNN)
|
| 15 |
+
|
| 16 |
+
A ResNet-style CNN trained on HWDB1.0 to recognise **178 Chinese characters** + **Unknown**.
|
| 17 |
+
|
| 18 |
+
## What's new in v3
|
| 19 |
+
| Feature | v2 | v3 |
|
| 20 |
+
|---|---|---|
|
| 21 |
+
| Architecture | Plain CNN | ResNet-style residual blocks |
|
| 22 |
+
| Loss | Cross-entropy | Cross-entropy + label smoothing (0.1) |
|
| 23 |
+
| Optimizer | Adam | AdamW (weight decay 1e-4) |
|
| 24 |
+
| Augmentation | Rotation, shift, zoom | + Shear, stronger zoom |
|
| 25 |
+
| Temperature scaling | Yes (buggy) | Removed (not needed) |
|
| 26 |
+
| Config | Scattered | Central CFG dict |
|
| 27 |
+
|
| 28 |
+
## Model details
|
| 29 |
+
| Item | Value |
|
| 30 |
+
|---|---|
|
| 31 |
+
| Input | 40×40 grayscale image |
|
| 32 |
+
| Classes | 179 (178 Chinese characters + Unknown) |
|
| 33 |
+
| Framework | Keras / TensorFlow |
|
| 34 |
+
| Confidence threshold | 0.3 |
|
| 35 |
+
| OOD training data | EMNIST Balanced (8% of training set) |
|
| 36 |
+
|
| 37 |
+
## Quick start
|
| 38 |
+
```python
|
| 39 |
+
import numpy as np, json
|
| 40 |
+
import tensorflow as tf
|
| 41 |
+
from tensorflow import keras
|
| 42 |
+
|
| 43 |
+
model = keras.models.load_model('chinese_hsk1_model_v3.keras')
|
| 44 |
+
label_map = json.load(open('label_map_v3.json', encoding='utf-8'))
|
| 45 |
+
cfg = json.load(open('config_v3.json'))
|
| 46 |
+
THRESHOLD = cfg['threshold']
|
| 47 |
+
|
| 48 |
+
def predict(img_gray):
|
| 49 |
+
x = img_gray.astype('float32') / 255.0
|
| 50 |
+
x = x.reshape(1, cfg['img_size'], cfg['img_size'], 1)
|
| 51 |
+
probs = model.predict(x)[0]
|
| 52 |
+
conf = probs.max()
|
| 53 |
+
idx = probs.argmax()
|
| 54 |
+
char = label_map[str(idx)]
|
| 55 |
+
if char == 'Unknown' or conf < THRESHOLD:
|
| 56 |
+
return 'Unknown', conf
|
| 57 |
+
return char, conf
|
| 58 |
+
```
|