1. 程式人生 > >Tensorflow框架兩種cost函式:MSE和Multi-class

Tensorflow框架兩種cost函式:MSE和Multi-class

import tensorflow as tf

def MSE_cost(out,Y):
    cost = tf.reduce_mean(tf.square(out-Y))
    return cost

def multiclass_cost(out,Y):
    cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(logits=out,labels=Y))
    return cost

tf.reduce_mean就是求平均值,預設axis情況下:矩陣(不分行列)所有元素求平均。