Open suntaochun opened 4 years ago
Compatibility between tensorflow.keras and Keras. With tensorflow2.0.0 this problem did not occur.
Hi. Is there any future updated version to solve this problem of compatibility? Or is there any possibility to use TensorFlow.Keras instead of Keras or vice versa to modify the code to use in TensorFlow v2.2 (because I realy love the convenience of using TensorLayer)? Big THANKS!
I tested tutorial_keras.py on tensorflow2.2,keras2.4.3 , the code works.
I suspect its due to lower keras and/or tensorflow versions.
Hi @Laicheng0830 . Thanks for your help. I have already tried your solution (upgrading Keras to v2.4.3) but failed.
However, I find what might be the crux of this problem. I track the problem and find that the basic for Model to generically be used in Network is that the core.py
introduces Layer class, and in the 213 line of that file the Model class tries to identify whether the Layer is the instance of a tensor of Tensorflow using tf_ops._TensorLike
or tf_ops._is_dense_tensor_like
where tf_ops
is tensorflow.python.ops
.
However the tensorflow.python.ops
, or tf_ops
doesn't include _TensorLike attribute in version 2.20 (thanks to Kite's AI search I search for all the possible method to identify the type of tensor), so I modify the code in core.py
such that:
if tf_ops.is_dense_tensor_like(check_argu): pass
instead of the original one. And the code works. I don't know whether this is the root of compatibility for this problem or just a bug. However I think maybe for user of v2.2 this is a universal problem because of the change in its core ops APIs. And I may be happy if it helps and you helped me with this issue.
Appendix: It works.
Hi @suntaochun!
Super thanks for your solution, it helps me too.
Just to clarify:
Need to change tensorlayers core.py file, which is (for me)
/home/user/.local/lib/python3.8/site-packages/tensorlayer/models/
213 line: change on if tf_ops.is_dense_tensor_like(check_argu):
223 line: change on if not tf_ops.is_dense_tensor_like(check_argu[idx]):
It allowed me to use tensorlayer 2.2.3 with tensorflow-gpu 2.4.0 and cuda 11.0. Tested on RL examples.
@MoscowskyAnton I'm very happy my solution helps you with your problem, and also thanks for your unique contribution!
New Issue Checklist
Issue Description
Traceback (most recent call last): File "d:\Test_Programs\PYTHON\tensorlayer_keras.py", line 31, in
network = tl.models.Model(inputs=ni, outputs=nn)
File "D:\Anaconda\lib\site-packages\tensorlayer\models\core.py", line 213, in init
if isinstance(check_argu, tf_ops._TensorLike) or tf_ops.is_dense_tensor_like(check_argu):
AttributeError: module 'tensorflow.python.framework.ops' has no attribute '_TensorLike'
Reproducible Code
My code is :