[英]Why tf.keras dosen't work but tensorflow.keras does even though tensorflow is imported as tf?
I've used the following lines of code:我使用了以下代码行:
!pip install --upgrade tensorflow
import tensorflow as tf
from tensorflow.keras import models
- this works fine from tensorflow.keras import models
- 这工作正常
BUT但
When from tf.keras import models
is used, error appears使用
from tf.keras import models
时出现错误
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-5-15abaed607f8> in <module>()
----> 1 from tf.keras import models
ModuleNotFoundError: No module named 'tf'
---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.
To view examples of installing some common dependencies, click the
"Open Examples" button below.
---------------------------------------------------------------------------
Why is this happening?为什么会这样?
Packages are stored in the computers as folders.包作为文件夹存储在计算机中。 For example, there is a xgboost folder if you import that.
例如,如果您导入它,则会有一个 xgboost 文件夹。 When you type
当您键入
from tf.keras import models
Python will look for a 'tf' reference (package) in your system, which does not exist, tf just exist as an alias in your python IDE. Python 将在您的系统中查找不存在的“tf”引用(包),tf 只是作为别名存在于您的 python IDE 中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.