[英]How to choose from "tensorflow.keras" and "tensorflow.python.keras" in tensorflow 2.0?
Currently in tensorflow 2.0, Keras
can be imported by both tensorflow.keras
and tensorflow.python.keras
.目前在tensorflow 2.0, Keras
可以通过两种进口tensorflow.keras
和tensorflow.python.keras
。 What's the difference and how should I choose from these two imports?这两个进口有什么区别,我应该如何选择?
from tensorflow.keras import *
from tensorflow.python.keras import *
From my understanding, tensorflow.python.keras
is pretty much the same as the python package Keras, while tensorflow.keras
is implemented by TensorFlow which might be more compatible with TF, but do not have all packages as in Keras such as Layer, InputSpec, etc.根据我的理解, tensorflow.python.keras
与 python 包tensorflow.python.keras
几乎相同,而tensorflow.keras
是由 TensorFlow 实现的,它可能与 TF 更兼容,但没有 Keras 中的所有包,例如 Layer、InputSpec , 等等。
One other issue is that for some IDEs like PyCharm, they cannot find or auto-complete packages from tensorflow.keras
, and the temporary solution is to use tensorflow.python.keras
instead.另一个问题是,对于像 PyCharm 这样的一些 IDE,他们无法从tensorflow.keras
找到或自动完成包,临时解决方案是使用tensorflow.python.keras
。 (from tensorflow issue ) (来自张量流问题)
In TensorFlow 2.0, tf.keras is recommended.在 TensorFlow 2.0 中,推荐使用 tf.keras。 This version is stable now.这个版本现在稳定了。
tensorflow.keras
and tensorflow.python.keras
are exactly the same package, what tells you that they are different? tensorflow.keras
和tensorflow.python.keras
是完全相同的包,是什么告诉你它们不同?
You are not supposed to use tensorflow.python
imports directly, as per this answer: https://stackoverflow.com/a/47306203/6108843你不应该直接使用tensorflow.python
导入,根据这个答案: https : tensorflow.python
从 Tensorflow 的最新版本开始,建议使用 tensorflow.keras 这可能是因为 TF 发展迅速,因此可能会贬值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.