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