ChrisMoe/handwriting-v5
023
Chinese Handwriting Recognition — HSK1 v5 (ResNet CNN + Embedding Verification)
A ResNet-style CNN trained on HWDB1.0 to recognise 178 Chinese characters + Unknown, with an embedding-template verification head for handwriting-practice apps.
What's new in v5
What's new in v4
Model details
Quick start — verification mode
import numpy as np, json
import tensorflow as tf
from tensorflow import keras
model = keras.models.load_model('chinese_hsk1_model_v5.keras')
embedding_model = keras.Model(model.input, model.layers[-2].output)
tpl_npz = np.load('templates_v5.npz')
templates = dict(zip(tpl_npz['chars'].tolist(), tpl_npz['embeddings']))
def verify(img_gray, target_char, sim_threshold=0.65):
x = img_gray.astype('float32') / 255.0
x = x.reshape(1, 40, 40, 1)
emb = embedding_model.predict(x, verbose=0)[0]
emb = emb / (np.linalg.norm(emb) + 1e-8)
if target_char not in templates:
return 'invalid_target', 0.0
sim = float(np.dot(emb, templates[target_char]))
return ('correct' if sim >= sim_threshold else 'incomplete_or_unclear'), sim