1、加入gradient clipping:
????例如用的是交叉熵cross_entropy = -tf.reduce_sum(y_*tf.log(y_conv))的話,最后softmax層輸出y_conv的取值范圍在[0,1]頁就是說允許取0值饼煞,有l(wèi)og(0)出現(xiàn)很有可能出現(xiàn)nan源葫,cross_entropy = -tf.reduce_mean(y_*tf.log(tf.clip_by_value(y_conv,1e-15,1.0))),在tensorflow中可以限定一下y_conv的取值范圍砖瞧。
with tf.name_scope('cross_entropy'):
? ? cross_entropy_mean = tf.losses.sparse_softmax_cross_entropy(labels=ground_truth_input, logits=logits)
????把上面的替換成下面的:
with tf.name_scope('cross_entropy'):
? ? one_hot_ground_truth_input = tf.one_hot(ground_truth_input, model_settings['label_count'])
? ? softmax = tf.nn.softmax(logits)
? ? cross_entropy_mean = -tf.reduce_mean(one_hot_ground_truth_input * tf.log(tf.clip_by_value(softmax, 1e-15, 1.0)))
2息堂、修改參數(shù)初始化方法:
????對(duì)于CNN可用xavier或者msra的初始化方法。
3块促、數(shù)據(jù)歸一化:
? ? 3.1 白化:減均值荣堰、除方差;
? ? 3.2 加入normalization竭翠,比如BN振坚、L2 norm等。
4逃片、減小學(xué)習(xí)率屡拨、或者batch size;