Full code is here
The error:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-6-e6c5369957bc> in <module>()
55 print(feed_dict)
56 _ , loss_val = sess.run(tr_op,
---> 57 feed_dict=feed_dict)
58 print('Loss of the current batch is {}'.format(loss_val))
TypeError: 'NoneType' object is not iterable
The following code is run before that call is executed:
print(type(tr_op))
print(type(feed_dict))
try:
some_object_iterator = iter(feed_dict)
except TypeError as te:
print (feed_dict, 'is not iterable')
print(feed_dict)
which yields the output:
<class 'tensorflow.python.framework.ops.Operation'>
<class 'dict'>
{<tf.Tensor 'img_data:0' shape=(?, 64, 64, 3) dtype=float32>: array([[[[0.3019608 , 0.23921569, 0.58431375],
[0.30588236, 0.23921569, 0.61960787],
[0.30980393, 0.24705882, 0.63529414],
...,
So the object that should be iterable is clearly iterable because it isnt raising the exception when I try to make an iterator out of it, and both objects both have clearly defined types. This error is not in the TensorFlow file for session, and I dont know where it was raised because there is no trace.
Thanks for any help
The error “TypeError: 'NoneType' object is not iterable” occurs when you try to iterate over a NoneType object. Objects like list, tuple, and string are iterables, but not None. To solve this error, ensure you assign any values you want to iterate over to an iterable object.
The Python "TypeError: 'NoneType' object is not iterable" occurs when we try to iterate over a None value. To solve the error, figure out where the variable got assigned a None value and correct the assignment or check if the variable doesn't store None before iterating.
The TypeError: 'NoneType' object is not iterable error is raised when you try to iterate over an object whose value is equal to None. To solve this error, make sure that any values that you try to iterate over have been assigned an iterable object, like a string or a list.
The Python "TypeError: argument of type 'NoneType' is not iterable" occurs when we use the membership test operators (in and not in) with a None value. To solve the error, correct the assignment of the variable that stores None or check if it doesn't store None .
Looks like your issue is here:
_ , loss_val = sess.run(tr_op, feed_dict=feed_dict)
You are asking tensorflow to compute the tr_op
for you. That is one operation. E.g. one return value from sess.run
will be produced. You are trying to extract 2 values from the result. It's trying to treat the return value of None
as a tuple in this case.
Try this to see it:
result = sess.run(tr_op, feed_dict=feed_dict)
print(result)
You'll see that result is None
, which is correct return value for an optimizer (tr_op
). If you further attempted:
_, loss_val = result
You would again get your error TypeError: 'NoneType' object is not iterable
.
What you meant to do probably is this:
_ , loss_val = sess.run([tr_op, loss_op], feed_dict=feed_dict)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With