Last active
November 15, 2019 21:29
-
-
Save Kida007/b641f153035c2127064ce4fe42647416 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def optimize(nn_last_layer, correct_label, learning_rate, num_classes): | |
# Reshape 4D tensors to 2D, each row represents a pixel, each column a class | |
logits = tf.reshape(nn_last_layer, (-1, num_classes), name="fcn_logits") | |
correct_label_reshaped = tf.reshape(correct_label, (-1, num_classes)) | |
# Calculate distance from actual labels using cross entropy | |
cross_entropy = tf.nn.softmax_cross_entropy_with_logits(logits=logits, labels=correct_label_reshaped[:]) | |
# Take mean for total loss | |
loss_op = tf.reduce_mean(cross_entropy, name="fcn_loss") | |
# The model implements this operation to find the weights/parameters that would yield correct pixel labels | |
train_op = tf.train.AdamOptimizer(learning_rate=learning_rate).minimize(loss_op, name="fcn_train_op") | |
return logits, train_op, loss_op | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment