Deep Learning with TensorFlow by Giancarlo Zaccone

Deep Learning with TensorFlow by Giancarlo Zaccone

Author:Giancarlo Zaccone
Language: eng
Format: epub
Publisher: Packt Publishing
Published: 2017-04-24T11:10:53+00:00


def loss(pred, label):

cross_entropy_loss = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(logits=pred, labels=label))

tf.summary.scalar('Entropy', cross_entropy_loss) reg_losses = tf.add_n(tf.get_collection("losses"))

tf.scalar_summary('Reg_loss', reg_losses)

return cross_entropy_loss + REGULARIZATION * reg_losses

def train(loss, step):

return tf.train.AdamOptimizer(LEARNING_RATE).

minimize(loss, global_step=step)

def get_next_batch(images, labels, step):

offset = (step * BATCH_SIZE) % (images.shape[0] - BATCH_SIZE)

batch_images = images[offset: offset + BATCH_SIZE]

batch_labels = labels[offset:offset + BATCH_SIZE]

return batch_images, batch_labels



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.