Rafay Khan
2 min readMay 11, 2020

--

Valborsf Sorry for the late reply, I was just hammered with work. Thanks to your follow up question I actually dug deep in my notes for my blog and found some inconsistencies with my previous answer.

When I first wrote the blog at that time I was using TensorFlow 1.8 with Keras 2.x.x version. A lot of changes have happened since then and with the integration of Keras now a fundamental part of TensorFlow 2.0 I need to correct myself.

When Keras and Tensorflow were separate entities, to conform with TensorFlow function call for sigmoid_cross_entropy_with_logits Keras converts the output of a sigmoid node to logits, as in my blog. You can confirm this in the older source code, too.

def binary_crossentropy(output, target, from_logits=False):
"""Binary crossentropy between an output tensor and a target tensor.
# Arguments
output: A tensor.
target: A tensor with the same shape as `output`.
from_logits: Whether `output` is expected to be a logits tensor.
By default, we consider that `output`
encodes a probability distribution.
# Returns
A tensor.
"""
# Note: tf.nn.softmax_cross_entropy_with_logits
# expects logits, Keras expects probabilities.
if not from_logits:
# transform back to logits
epsilon = _to_tensor(_EPSILON, output.dtype.base_dtype)
output = tf.clip_by_value(output, epsilon, 1 - epsilon)
output = tf.log(output / (1 - output))
return tf.nn.sigmoid_cross_entropy_with_logits(labels=target,
logits=output)

(reference: https://github.com/keras-team/keras/blob/c45f48eaeab2a9c9a809488950f07d83abe18411/keras/backend/tensorflow_backend.py#L2595)

Now that Keras in integrated into TensorFlow, Keras does not need to perform these “cheap” tricks to conform its sigmoid output to Tensorflow. It can just go one step back in the computation graph and pick the inputs to the Sigmoid Node, which are still technically logits, and use them to compute sigmoid_cross_entropy_with_logits . This is what the code is doing in my previous answer in the “else” part.

Now coming back to your question on a debugger for Keras and TensorFlow, I mainly use PyCharm for that. I feel it currently serves my needs perfectly.

BTW thanks for bringing up your original question. I’ll update the original post to reflect the changes in TensorFlow to avoid confusion for future readers. 🙂

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Rafay Khan
Rafay Khan

No responses yet

Write a response