Upon copying retrain.py from the TensorFlow GitHub repository
And then opening it in PyCharm
, on lines 794 and 802 PyCharm
shows the following warning:
Type 'Variable' doesn't have expected attribute '__sub__'
Here is a screenshot if that helps:
Can somebody please explain:
What does this mean?
How can this be resolved or the warning suppressed?
Clearly PyCharm thinks that layer_weights
does not have an attribute "__sub__"
, but what does this mean and why would a __sub__
attribute be necessary? The function variable_summaries()
does not refer to an attribute __sub__
(copied/pasted starting at line 735):
def variable_summaries(var):
"""Attach a lot of summaries to a Tensor (for TensorBoard visualization)."""
with tf.name_scope('summaries'):
mean = tf.reduce_mean(var)
tf.summary.scalar('mean', mean)
with tf.name_scope('stddev'):
stddev = tf.sqrt(tf.reduce_mean(tf.square(var - mean)))
tf.summary.scalar('stddev', stddev)
tf.summary.scalar('max', tf.reduce_max(var))
tf.summary.scalar('min', tf.reduce_min(var))
tf.summary.histogram('histogram', var)
# end of function
Can somebody explain why an attribute __sub__
would be necessary?
After reading the this post, I'm under the impression that a comment to suppress this warning could be added, possibly something like:
@type whatGoesHere: ??
@attribute __sub__: comment here?? # is this correct?
@param whatGoesHere: ??
Is something like this doable, and what should the comment be?
I prefer to not disable PyCharm's warnings as I find them helpful in many cases. Can somebody please provide some enlightenment on the above so as to avoid disabling this warning in PyCharm?
- Edit:
Thanks for the explanation Shu. For the moment this seems to be the best way to deal with this in PyCharm without disabling that inspection entirely:
# this comment is necessary to suppress an unnecessary PyCharm warning
# noinspection PyTypeChecker
variable_summaries(layer_weights)
If eventually somebody could inform me of a better option that would be great.