记录了一些使用 keras 的技巧。
categorical_crossentropy vs sparse_categorical_crossentropy.
3. The Answer, In a Nutshell
-
If your targets are one-hot encoded, use categorical_crossentropy.
-
Examples of one-hot encodings:
-
[1,0,0]
-
[0,1,0]
-
[0,0,1]
-
But if your targets are integers, use sparse_categorical_crossentropy.
-
Examples of integer encodings (for the sake of completion):
- 1, 2, 3
clip norm
https://wulc.me/2018/05/01/%E6%A2%AF%E5%BA%A6%E8%A3%81%E5%89%AA%E5%8F%8A%E5%85%B6%E4%BD%9C%E7%94%A8/
可以加速 RNN 训练
Multiple GPU
# https://keras.io/utils/#multi_gpu_model#
使用多GPU,注意使用 save 的时候,传参传 model (multi_gpu_model的model参数)
Encode Labels
可以把不同的字符[‘aa’, ‘bb’, ‘cc’, ‘aa’] 编码成 [0, 1, 2, 0]
1 2 3 4 5 6 |
训练中存在的问题
训练性能低了别急着调参,首先看看数据预处理有没有问题,评价指标是不是写错了。再一个,batch norm 要勤快点加上。
相似的文章还有:https://svtter.github.io/2018/02/01/keras%e5%9d%91/