Computing loss

Compute the loss using cross entropy. We know that the cross-entropy loss is given as follows:

Here, is the actual label and is the predicted label. Thus, the cross-entropy loss is implemented as follows:

cross_entropy = -tf.reduce_sum(y*tf.log(YHat))

Minimize the loss using the Adam optimizer:

optimizer = tf.train.AdamOptimizer(1e-4).minimize(cross_entropy)

Calculate the accuracy:

predicted_digit = tf.argmax(y_hat, 1)
actual_digit = tf.argmax(y, 1)

correct_pred = tf.equal(predicted_digit,actual_digit)
accuracy = tf.reduce_mean(tf.cast(correct_pred, tf.float32))
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset