我正在迷失方向:使用自定义迷失时,张量流中的难点
损失功能代码:
def compute_cost(A,Y):
cost = tf.math.divide(tf.math.multiply(-1.0, tf.reduce_sum(tf.math.multiply(Y, tf.math.log(A)) + tf.math.multiply( tf.math.subtract(1.0, Y), tf.math.log(tf.math.subtract(1.0, A))))), tf.cast(tf.size(Y), tf.float32))
return cost
型号:
model = tf.keras.Sequential([
tf.keras.layers.Dense(32, activation = 'relu', input_shape= (784,)),
tf.keras.layers.Dense(32, activation = 'relu'),
tf.keras.layers.Dense(10, activation = 'softmax')])
model.compile(
loss = compute_cost,
optimizer = 'adam',
metrics = ['accuracy']
)
任何解决方案