Guest User

Untitled

a guest
Apr 23rd, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. def optimize(nn_last_layer, correct_label, learning_rate, num_classes):
  2.  
  3. # Reshape 4D tensors to 2D, each row represents a pixel, each column a class
  4. logits = tf.reshape(nn_last_layer, (-1, num_classes), name="fcn_logits")
  5. correct_label_reshaped = tf.reshape(correct_label, (-1, num_classes))
  6.  
  7. # Calculate distance from actual labels using cross entropy
  8. cross_entropy = tf.nn.softmax_cross_entropy_with_logits(logits=logits, labels=correct_label_reshaped[:])
  9. # Take mean for total loss
  10. loss_op = tf.reduce_mean(cross_entropy, name="fcn_loss")
  11.  
  12. # The model implements this operation to find the weights/parameters that would yield correct pixel labels
  13. train_op = tf.train.AdamOptimizer(learning_rate=learning_rate).minimize(loss_op, name="fcn_train_op")
  14.  
  15. return logits, train_op, loss_op
Add Comment
Please, Sign In to add comment