Tensorflow.keras.layers“未解决的参考"在 pycharm 中 [英] Tensorflow.keras.layers "unresolved reference" in pycharm

查看:35
本文介绍了Tensorflow.keras.layers“未解决的参考"在 pycharm 中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚安装了 tensorflow,并且正在尝试让基础工作发挥作用.但是,导入语句以红色下划线标出,并带有消息未解析的引用'层'".不过代码确实运行正常.

I just installed tensorflow, and am trying to get the basics to work. However, the import statement is underlined in red, with message "unresolved reference 'layers' ". The code does run correctly though.

我已经尝试了这个问题中的一些建议:PyCharm显示有效代码的未解决引用错误.

I've tried some of the suggestions in this question: PyCharm shows unresolved references error for valid code.

然而,这个问题与我的具体错误无关,我想知道我的错误的原因是什么,它是否只是 pycharm 级错误的一部分,或者与 tensorflow 相关的某些东西.

However, that question is not about my specific error, and I'm wondering what the cause of my error is, and whether it is just part of a pycharm-level bug, or something related to tensorflow.

我的代码是:

import tensorflow as tf;
from tensorflow.keras import layers;

它在图层"下方的红色锯齿状下划线上给出错误未解析的参考'图层'",但没有说明如何解决它.

It gives the error "unresolved reference 'layers' " on a red jagged underline beneath "layers", with no indication of how to solve it.

推荐答案

如果您使用的是 Tensorflow 2.0,请尝试使用此代码来加载它们,而不是使用 'from' 和 'import'

If you are using Tensorflow 2.0, try using this code to load them instead using 'from' and 'import'

import tensorflow
example_model = tensorflow.keras.Sequential()
BatchNormalization = tensorflow.keras.layers.BatchNormalization
Conv2D = tensorflow.keras.layers.Conv2D
MaxPooling2D = tensorflow.keras.layers.MaxPooling2D
Activation = tensorflow.keras.layers.Activation
Flatten = tensorflow.keras.layers.Flatten
Dropout = tensorflow.keras.layers.Dropout
Dense = tensorflow.keras.layers.Dense

##Testing Purpose On PyCharm##
example_model.add(Conv2D(64, (3, 3), activation='relu', padding='same', input_shape=(100, 100, 1)))
example_model.add(MaxPooling2D((2, 2)))
example_model.add(Flatten())
example_model.summary()

这篇关于Tensorflow.keras.layers“未解决的参考"在 pycharm 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆