记录了一些使用 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

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]

<td>
  # encode class values as integers<br />encoder&nbsp;=&nbsp;LabelEncoder()<br />encoder.fit(Y)<br />encoded_Y&nbsp;=&nbsp;encoder.transform(Y)<br /># convert integers to dummy variables (i.e. one hot encoded)<br />dummy_y&nbsp;=&nbsp;np_utils.to_categorical(encoded_Y)
</td>

训练中存在的问题

训练性能低了别急着调参,首先看看数据预处理有没有问题,评价指标是不是写错了。再一个,batch norm 要勤快点加上。

相似的文章还有:https://svtter.github.io/2018/02/01/keras%e5%9d%91/