TypeError: Tensor objects are not iterable when eager execution is not enabled. To iterate over this tensor use tf.map_fn.
mosheliv opened this issue · 12 comments
Hi,
Trying to optimize pretty standard resnet50 model from keras and getting this:
Traceback (most recent call last):
File "rn50_inf.py", line 289, in <module>
model = reduce_keras_model(model)
File "/home/m/.local/lib/python2.7/site-packages/kito/__init__.py", line 371, in reduce_keras_model
for f in prev_layer:
File "/home/m/.local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 431, in __iter__
"Tensor objects are not iterable when eager execution is not "
TypeError: Tensor objects are not iterable when eager execution is not enabled. To iterate over this tensor use tf.map_fn.
keras 2.2.4
tf 1.10.0
Can you please run this script in your environment?
https://github.com/ZFTurbo/Keras-inference-time-optimizer/blob/master/kito/test_bench.py
attached
test_bench.txt
And now the same but change line
models_to_test = ['mobilenet_small']
to
models_to_test = ['resnet50']
attached
test_bench.txt
ResNet50 from keras was successfully optimized on your machine. You probably have some error in your model. Can you print model.summary() for your implementation?
I think I know what the problem is. One of the issues state that it doesn't handle nested models well.
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
input_1 (InputLayer) (None, 512, 512, 3) 0
_________________________________________________________________
resnet50 (Model) (None, 2048) 23587712
_________________________________________________________________
dense_1 (Dense) (None, 28) 57372
=================================================================
Total params: 23,645,084
Trainable params: 23,591,964
Non-trainable params: 53,120
I actually had such case in test_bench.py: 'multi_model_layer' and it works fine. I will check your case and probably fix the code soon.
I fixed the problem. Your code should work fine now.
I have the same problem, could you tell me how to fix it?