简体   繁体   English

为什么 tf.keras 不起作用,但 tensorflow.keras 是否有效?

[英]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.

相关问题 Why tensorflow.keras and tensorflow.python.keras does not work? - Why tensorflow.keras and tensorflow.python.keras does not work? 在 tf.keras 中使用 tensorflow 函数 - using tensorflow functions with tf.keras 将tf.Keras与Tensorflow优化器一起使用 - Use tf.Keras with Tensorflow optimizer 使用基本的低级TensorFlow训练循环训练tf.keras模型不起作用 - Training a tf.keras model with a basic low-level TensorFlow training loop doesn't work 不支持 TensorFlow 2.0 的 Keras。 我们建议使用“tf.keras”,或者降级到 TensorFlow 1.14 - Keras that does not support TensorFlow 2.0. We recommend using `tf.keras`, or alternatively, downgrading to TensorFlow 1.14 为什么在转换为张量流估计量后,这种简单的tf.keras模型无法训练? - Why does this simple tf.keras model not train after converting to a tensorflow estimator? 如何从 Tensorflow 中的 tf.keras 导入 keras? - How to import keras from tf.keras in Tensorflow? 用tf.keras将TensorFlow重新写入Keras - Re-write TensorFlow into Keras with tf.keras 即使安装了 tensorflow 和 keras,Python 也不会让我导入 tensorflow.keras? - Python won't let me import tensorflow.keras even though tensorflow and keras are both installed? Foolbox和tf.keras(在tensorflow中复制keras) - foolbox and tf.keras (keras copy within tensorflow)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM