简体   繁体   English

导入 tensorflow.python.keras 而不是 tensorflow.keras

[英]Import tensorflow.python.keras instead of tensorflow.keras

The autocomplete function of VS Code 1.41.1 does not work for example for VS Code 1.41.1 的自动完成功能不适用于例如

from tensorflow.keras import layers

(for tensorflow version 1.14.0) but it works for (对于 tensorflow 版本 1.14.0)但它适用于

from tensorflow.python.keras import layers

So what is the exact difference?那么具体的区别是什么? Why does it work in the latter case?为什么它在后一种情况下有效? And is it always safe to replace the first method with the second, meaning it produces identical behavior by using the exact same methods?用第二种方法替换第一种方法是否总是安全的,这意味着它通过使用完全相同的方法产生相同的行为?

So, thanks to thushv89 and some additional research I found some kind of explanation and solution:所以,多亏了 sohv89 和一些额外的研究,我找到了某种解释和解决方案:

https://github.com/microsoft/python-language-server/issues/818 https://github.com/microsoft/python-language-server/issues/818

The way TensorFlow handels imports cannot be read by VS Code easily. VS Code 无法轻松读取 TensorFlow 处理导入的方式。 Using tf.python.keras is a work around, but definitely not recommended.使用tf.python.keras是一种解决方法,但绝对不推荐。 Other ways to solve this issue are described here:此处描述了解决此问题的其他方法:

https://github.com/tensorflow/tensorflow/issues/32982 https://github.com/tensorflow/tensorflow/issues/32982

使用 tensorflow 2.2 版时已解决此问题。

声明:本站的技术帖子网页,遵循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? 如何从 tensorflow 2.0 中的“tensorflow.keras”和“tensorflow.python.keras”中进行选择? - How to choose from "tensorflow.keras" and "tensorflow.python.keras" in tensorflow 2.0? keras 与 tensorflow.python.keras - 使用哪一个? - keras vs. tensorflow.python.keras - which one to use? 即使安装了 tensorflow 和 keras,Python 也不会让我导入 tensorflow.keras? - Python won't let me import tensorflow.keras even though tensorflow and keras are both installed? Keras模型到tensorflow.keras - Keras model to tensorflow.keras AttributeError:模块'tensorflow.python.keras'没有属性'abs' - AttributeError: module 'tensorflow.python.keras' has no attribute 'abs' Z23EEEB4347BDD26BFC6B7EE9A3B755DD 中 keras 和 tensorflow.keras 之间的意外性能差异 - Unexpected performance differences between keras and tensorflow.keras in python AttributeError:模块“tensorflow.python.keras”没有属性“应用程序” - AttributeError: module 'tensorflow.python.keras' has no attribute 'applications' 无法在 VS 代码中导入 tensorflow.keras - Can't import tensorflow.keras in VS Code Python 中带有 Tensorflow.keras 的全局深度神经网络 - Global deep neural network with Tensorflow.keras in Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM