Views
No views yet
| Feature | v2 | v3 |
|---|---|---|
| Architecture | Plain CNN | ResNet-style residual blocks |
| Loss | Cross-entropy | Cross-entropy + label smoothing (0.1) |
| Optimizer | Adam | AdamW (weight decay 1e-4) |
| Augmentation | Rotation, shift, zoom | + Shear, stronger zoom |
| Temperature scaling | Yes (buggy) | Removed (not needed) |
| Config | Scattered | Central CFG dict |
| Item | Value |
|---|---|
| Input | 40×40 grayscale image |
| Classes | 179 (178 Chinese characters + Unknown) |
| Framework | Keras / TensorFlow |
| Confidence threshold | 0.3 |
| OOD training data | EMNIST Balanced (8% of training set) |
1import numpy as np, json
2import tensorflow as tf
3from tensorflow import keras
4
5model = keras.models.load_model('chinese_hsk1_model_v3.keras')
6label_map = json.load(open('label_map_v3.json', encoding='utf-8'))
7cfg = json.load(open('config_v3.json'))
8THRESHOLD = cfg['threshold']
9
10def predict(img_gray):
11 x = img_gray.astype('float32') / 255.0
12 x = x.reshape(1, cfg['img_size'], cfg['img_size'], 1)
13 probs = model.predict(x)[0]
14 conf = probs.max()
15 idx = probs.argmax()
16 char = label_map[str(idx)]
17 if char == 'Unknown' or conf < THRESHOLD:
18 return 'Unknown', conf
19 return char, conf