Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
Add Comment
Please, Sign In to add comment