AttributeError怎么解决

import tensorflow as tf
sess = tf.InteractiveSession()
x = tf.placeholder(tf.float32,[None,784])
w = tf.Variable(tf.zeros([784,10]))
b = tf.Variable(tf.zeros([10]))
y = tf.nn.softmax(tf.matmul(x,w) + b)
y_ = tf.placeholder(tf.float32,[None,10])
cross_entropy = tf.reduce_mean(-tf.reduce_sum(y_ * tf.log(y),reduction_indices=[1]))
train_step = tf.train.GradientDescentOptimizer(0.5).minimize(cross_entropy)
tf.global_variables_initializer().run()
for i in range(1000):
batch_xs,batch_ys = mnist.train.next_batch(100)
train_step.run({x:batch_xs,y_:batch_ys})
correct_prediction = tf.equal(tf.argmax(y,1),tf.argmax(y_,1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction,tf.float32))
print(accuracy.eval({x:mnist.test.images,y_:mnist.test.labels}))

Traceback (most recent call last):
File "/home/zhudongmei/PycharmProjects/tensorflow/MNIST", line 10, in
tf.global_variables_initializer().run()
AttributeError: 'module' object has no attribute 'global_variables_initializer'

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
AttributeError
Traceback (most recent call last):rn File "model_test.py", line 20, in rn import commonrn File "/home/tl/deeplab/common.py", line 45, in rn flags.DEFINE_enum('model_variant', 'xception_65', ['xception_65'],rnAttributeError: module 'tensorflow.python.platform.flags' has no attribute 'DEFINE_enum'rnrncommom.py,line45:rnflags.DEFINE_enum('model_variant', 'xception_65', ['xception_65'],rn 'DeepLab model variants.')rnrn
(已解决)with语句常见错误AttributeError: __enter__
连接MySQL过程中, with con: cur = con.cursor() cur.executemany(final_str, symbols) 出现如下错误: 关乎with语句的用法,有上下文管理器,with 语句才能工作。 上下文管理器必须同时提供 __enter__() 和 __exit__() 方法的定义,缺少任何一个都会导致 AttributeError;wi...
Python AttributeError异常
遇到一个很奇怪的问题,本人刚学习Python ,在学类与对象的方法时,在调用方法时,我的对象名取名为k ,然而死活就是报AttributeError异常; 在反复检查代码无误后,然后我试着改一下名字,奇迹出现了,名字一改就好了,我以为不能使用单个字母,抱着试一试的心态,我将对象名改为a ,奇迹再次出现,成功了!!!规则不是很懂,还请大神指教nn```n class Person:n population=0n def __init__(self,name):n self.name=namen print '(Initializing %s)'%self.namen Person.population+=1n def __del__(self):n print'%s says bye.'%self.namen Person.population-=1n if Person.population==0:n print 'I am the last one.'n else:n print 'There are still %d people left.'% Person.populationn def sayHi(self):n print 'Hi,my name is %s.' % self.namen def howMany(self):n if Person.population==1:n print 'I am the only person here.'n else :n print 'We have %d persons here.' % Person.populationnswaroop=Person('swaroop')nswaroop.sayHi()nswaroop.howMany()nn# 此处有问题 na=Person('Abdul Kalam')na.sayHi()na.howMany()nnswaroop.sayHi()nswaroop.howMany()n```nn
python安装theano出现AttributeError错误解决办法
一、版本:theano为1.03,numpy为1.16.0,python版本为3.6 二、问题描述:AttributeError: ('The following error happened while compiling the node', Elemwise{Composite{((i0 * i1) + i2)}}(weight, input, bias), '\n', "module '...
python:AttributeError:类没有属性‘***’
初学python遇到了问题rn按书上的代码敲的结果有BUGrnrn显示这个[color=#FF0000]File "D:/PycharmProjects/chapter9/electric_car.py", line 52, in rn my_tesla.battery.describe_battery()rnAttributeError: 'ElectricCar' object has no attribute 'battery'[/color]rnrnclass Car():rnrn def __init__(self, make, model, year):rn self.make = makern self.model = modelrn self.year = yearrn self.odometer_reading = 0rnrn def get_descriptive_name(self):rn long_name = str(self.year) + ' ' + self.make + ' ' + self.modelrn return long_name.title()rnrn def read_odometer(self):rn print("This car has " + str(self.odometer_reading) + " miles on it.")rnrn def update_odometer(self, mileage):rn if mileage >= self.odometer_reading:rn self.odometer_reading = mileagern else:rn print("You can't roll backk an odometer!")rnrn def increment_odometer(self, miles):rn self.odometer_reading += milesrnrnrnclass Battery():rn """一次模拟电动汽车电瓶的简单尝试"""rnrn def _init_(self, battery_size=70):rn """初始化电瓶属性"""rn self.battery_size = battery_sizernrn def describe_battery(self):rn """打印一条描述电瓶容量的消息"""rn print("This car has a " + str(self.battery_size) + "-kWh battery.")rnrnrnclass ElectricCar(Car):rn """电动汽车的独特之处"""rnrn def _init_(self, make, model, year):rn """rn 电动汽车的独特之处rn 初始化父类的属性,再初始化电动汽车持有的属性rn """rn super()._init_(make, model, year)rn self.battery = Battery()rnrnrnmy_tesla = ElectricCar('tesla', 'model s', 2016)rnprint(my_tesla.get_descriptive_name())rnmy_tesla.battery.describe_battery()rn
报错AttributeError: 'QWidget' object has no attribute 'setCentralWidget'如何解决
# -*- coding: utf-8 -*-rnrn# Form implementation generated from reading ui file 'sign.ui'rn#rn# Created: Sun Nov 13 17:09:05 2016rn# by: PyQt4 UI code generator 4.11.3rn#rn# WARNING! All changes made in this file will be lost!rnrnimport sysrnfrom PyQt4 import QtCore, QtGuirnrntry:rn _fromUtf8 = QtCore.QString.fromUtf8rnexcept AttributeError:rn def _fromUtf8(s):rn return srnrntry:rn _encoding = QtGui.QApplication.UnicodeUTF8rn def _translate(context, text, disambig):rn return QtGui.QApplication.translate(context, text, disambig, _encoding)rnexcept AttributeError:rn def _translate(context, text, disambig):rn return QtGui.QApplication.translate(context, text, disambig)rnrnclass Ui_MainWindow(object):rn def setupUi(self, MainWindow):rn MainWindow.setObjectName(_fromUtf8("MainWindow"))rn MainWindow.resize(747, 564)rn self.centralwidget = QtGui.QWidget(MainWindow)rn self.centralwidget.setObjectName(_fromUtf8("centralwidget"))rn self.label = QtGui.QLabel(self.centralwidget)rn self.label.setGeometry(QtCore.QRect(50, 30, 211, 61))rn self.label.setStyleSheet(_fromUtf8("\n"rn"font: 75 22pt \"Microsoft YaHei UI\";"))rn self.label.setObjectName(_fromUtf8("label"))rn self.label_2 = QtGui.QLabel(self.centralwidget)rn self.label_2.setGeometry(QtCore.QRect(50, 120, 81, 18))rn self.label_2.setStyleSheet(_fromUtf8("font: 9pt \"Microsoft YaHei UI\";"))rn self.label_2.setObjectName(_fromUtf8("label_2"))rn self.lineEdit = QtGui.QLineEdit(self.centralwidget)rn self.lineEdit.setGeometry(QtCore.QRect(50, 150, 331, 25))rn self.lineEdit.setObjectName(_fromUtf8("lineEdit"))rn self.label_3 = QtGui.QLabel(self.centralwidget)rn self.label_3.setGeometry(QtCore.QRect(50, 200, 81, 18))rn self.label_3.setStyleSheet(_fromUtf8("font: 9pt \"Microsoft YaHei UI\";"))rn self.label_3.setObjectName(_fromUtf8("label_3"))rn self.lineEdit_2 = QtGui.QLineEdit(self.centralwidget)rn self.lineEdit_2.setGeometry(QtCore.QRect(50, 230, 331, 25))rn self.lineEdit_2.setObjectName(_fromUtf8("lineEdit_2"))rn self.label_4 = QtGui.QLabel(self.centralwidget)rn self.label_4.setGeometry(QtCore.QRect(50, 280, 81, 18))rn self.label_4.setStyleSheet(_fromUtf8("font: 9pt \"Microsoft YaHei UI\";"))rn self.label_4.setObjectName(_fromUtf8("label_4"))rn self.lineEdit_3 = QtGui.QLineEdit(self.centralwidget)rn self.lineEdit_3.setGeometry(QtCore.QRect(50, 310, 331, 25))rn self.lineEdit_3.setObjectName(_fromUtf8("lineEdit_3"))rn self.pushButton = QtGui.QPushButton(self.centralwidget)rn self.pushButton.setGeometry(QtCore.QRect(50, 380, 112, 34))rn self.pushButton.setStyleSheet(_fromUtf8("font: 9pt \"Microsoft YaHei UI\";\n"rn"background-color: rgb(215, 215, 215);"))rn self.pushButton.setObjectName(_fromUtf8("pushButton"))rn MainWindow.setCentralWidget(self.centralwidget)rn self.menubar = QtGui.QMenuBar(MainWindow)rn self.menubar.setGeometry(QtCore.QRect(0, 0, 747, 30))rn self.menubar.setObjectName(_fromUtf8("menubar"))rn MainWindow.setMenuBar(self.menubar)rn self.statusbar = QtGui.QStatusBar(MainWindow)rn self.statusbar.setObjectName(_fromUtf8("statusbar"))rn MainWindow.setStatusBar(self.statusbar)rnrn self.retranslateUi(MainWindow)rn QtCore.QMetaObject.connectSlotsByName(MainWindow)rnrn def retranslateUi(self, MainWindow):rn MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow", None))rn self.label.setText(_translate("MainWindow", "欢迎注册", None))rn self.label_2.setText(_translate("MainWindow", "名字", None))rn self.label_3.setText(_translate("MainWindow", "密码", None))rn self.label_4.setText(_translate("MainWindow", "重复密码", None))rn self.pushButton.setText(_translate("MainWindow", "注册", None))rnrnif __name__ == "__main__":rn app = QtGui.QApplication(sys.argv)rn Form = QtGui.QWidget()rn ui = Ui_MainWindow()rn ui.setupUi(Form)rn Form.show()rn sys.exit(app.exec_())rnrnPython菜鸟,想简单实现一个用户注册注册界面,还没有与数据库进行连接,运行时报错rnTraceback (most recent call last):rn File "D:/PyCharm 2016.2.3/example/Sign.py", line 88, in rn ui.setupUi(Form)rn File "D:/PyCharm 2016.2.3/example/Sign.py", line 64, in setupUirn MainWindow.setCentralWidget(self.centralwidget)rnAttributeError: 'QWidget' object has no attribute 'setCentralWidget'rnrn求大神告知解决办法。rnrnrn
AttributeError问题 求大佬解答
[img=https://img-bbs.csdn.net/upload/201801/09/1515429817_447527.png][/img]rnrn[code=python]from django.db import modelsrnrnclass Topic(models.Model):rn """用户学习的主题"""rn text = models.CharField(max_length=200)rn date_added = models.DataTimeField(auto_now_add=True)rnrn def _str_(self):rn '''返回模型的字符串表示'''rn return self.text[/code]rn rn脚本很简单 实在是不知道怎么出错了 就是运行不下去 求大佬解答啊
Python 3.7 AttributeError: 'str' object has no attribute 'items' 报错怎么解决
![图片说明](https://img-ask.csdn.net/upload/201901/23/1548240235_359645.png)rn求大佬帮忙看下这样的报错怎么解决
AttributeError: 'Settings' object has no attribute 'DATABASE_ENGINE'
环境:Centos、python2.7.7 Django:1.7 south:0.7rnsettings.py 里的部分配置:rnINSTALLED_APPS = (rn 'south',rn 'django.contrib.admin',rn 'django.contrib.auth',rn 'django.contrib.contenttypes',rn 'django.contrib.sessions',rn 'django.contrib.messages',rn 'django.contrib.staticfiles',rn 'polls'rn)rn其中south:为同步模型到数据库的第三方模块,用来取代syncdb。rnpolls:为自己的投票应用。rn目前我执行python manage.py syncdb或者python manage.py startmigration polls --initial均报错,报错信息如下:rnTraceback (most recent call last):rn File "manage.py", line 10, in rn execute_from_command_line(sys.argv)rn File "/usr/local/python2.7/lib/python2.7/site-packages/Django-1.7-py2.7.egg/django/core/management/__init__.py", line 385, in execute_from_command_linern utility.execute()rn File "/usr/local/python2.7/lib/python2.7/site-packages/Django-1.7-py2.7.egg/django/core/management/__init__.py", line 377, in executern self.fetch_command(subcommand).run_from_argv(self.argv)rn File "/usr/local/python2.7/lib/python2.7/site-packages/Django-1.7-py2.7.egg/django/core/management/__init__.py", line 238, in fetch_commandrn klass = load_command_class(app_name, subcommand)rn File "/usr/local/python2.7/lib/python2.7/site-packages/Django-1.7-py2.7.egg/django/core/management/__init__.py", line 41, in load_command_classrn module = import_module('%s.management.commands.%s' % (app_name, name))rn File "/usr/local/python2.7/lib/python2.7/importlib/__init__.py", line 37, in import_modulern __import__(name)rn File "/usr/local/python2.7/lib/python2.7/site-packages/South-0.6-py2.7.egg/south/management/commands/syncdb.py", line 5, in rn from south import migrationrn File "/usr/local/python2.7/lib/python2.7/site-packages/South-0.6-py2.7.egg/south/migration.py", line 17, in rn from south.db import dbrn File "/usr/local/python2.7/lib/python2.7/site-packages/South-0.6-py2.7.egg/south/db/__init__.py", line 9, in rn module_name = '.'.join(['south.db', settings.DATABASE_ENGINE])rn File "/usr/local/python2.7/lib/python2.7/site-packages/Django-1.7-py2.7.egg/django/conf/__init__.py", line 47, in __getattr__rn return getattr(self._wrapped, name)rn[color=#FF0000]AttributeError: 'Settings' object has no attribute 'DATABASE_ENGINE'[/color]
错误:“AttributeError: module 'aiml' has no attribute 'Kernel'
初学Python 3.X,按照网页上的关于aiml的例子写了如下代码,运行总是报错:rnC:\Users\lenovo\PycharmProjects\aimltest\venv\Scripts\python.exe C:/Users/lenovo/PycharmProjects/aimltest/test1.pyrnTraceback (most recent call last):rn File "C:/Users/lenovo/PycharmProjects/aimltest/test1.py", line 17, in rn alice=aiml.Kernel()rnAttributeError: module 'aiml' has no attribute 'Kernel'rnC:\Users\lenovo\PycharmProjects\aimltest\venv\lib\site-packages\aiml\alicernrnProcess finished with exit code 1rn检查了目录,aiml下面也有Kernel.py,请问如何解决,谢谢大侠!rn-----------------------源代码------------------------------------rnrn# -*- coding: utf-8 -*-rnimport aimlrnimport sysrnimport osrnrndef get_module_dir (name):rnrn path = getattr(sys.modules[name], '__file__', None)rn if not path:rn raise AttributeError('模块 %s 没有 属性 __file__'%name)rn return os.path.dirname(os.path.abspath(path))rnrnalice_path =get_module_dir('aiml') +'\\alice'rnrnos.chdir(alice_path)rnprint(alice_path)rnalice=aiml.Kernel()rnalice.learn("std-startup.xml")rnalice.respond("load aiml b")rnrnwhile True:rn print(alice.respond(input("Enter your message >>")))rnrn
Python出现属性错误(Attributeerror)的原因之一
检查类中构造函数__init__()是否写正确,左右两边各两条下划线
AttributeError: 'dict' object has no attribute 'status_code'
刚学python和django框架。出现的错误AttributeError: 'dict' object has no attribute 'status_code'这个错误是什么导致的?怎么解决?求大神指导!!!
AttributeError: 'module' object has no attribute 'rcParams'
电脑系统win7 x64rn电脑同时安装了python2.7和python3.4rn也同时安装了matplotlib for 2.7 和3.4rnrn在pycharm py文件中import matplotlib正常(解释器为python 3.4)rnprint(matplotlib.__file__ )rnD:\python3.4.2\lib\site-packages\matplotlib\__init__.pyrnrn但在python console中import matplotlib出现错误:(解释器也为python 3.4)rnAttributeError: 'module' object has no attribute 'rcParams'rnrn网上在解决说:(应该是针对linux)rnit looks like you have a matplotlib dir in your working directory that is being picked up and you probably don't want it. rnrnYou have the matplotlib source directory in your HOME directory and when you run from your home directory, it is being picked up instead of the installation directory. I usually name my src tree "mpl" to avoid this problem rn这个好像不行
AttributeError: module 'request' has no attribute 'args'
我在看flask教学视频rn模仿里面的代码rn@app.route('/login/')rndef login():rn print(request.args)rn print(request.args.get('q1'))rn return render_template('login.html')rnrnlogin.html里rnrnrnrn rn 登陆页面rnrnrn 点我搜索rnrnrnrn代码和视频基本一样,结果运行显示此帖标题字样,我的是py3.x,不知道是不是这个原因,没有args这个方法
python AttributeError: _exit_ 这是什么错误
python AttributeError: _exit_ 这是什么错误
AttributeError: '_NamespacePath' oject has no attribute 'sort'
win10 环境。安装anaconda,python3.6。能运行python程序,但是输入pip list,或者其他pip命令,jupyter notebook。都会报这个错误。rn错误的详细截图:rn[img=https://img-bbs.csdn.net/upload/201704/01/1491056337_884908.png][/img]rn请问大神怎么解决?
AttributeError: '_NamespacePath' object has no attribute 'sort'
python3.6安装six包报错,报错信息为:AttributeError: '_NamespacePath' object has no attribute 'sort'rn执行pip list命令也报同样的错。rn环境为64位windows 10,已安装anaconda3rn求大神指导,谢谢![img=https://img-bbs.csdn.net/upload/201705/16/1494935625_44723.png][/img]
django调mysql报 AttributeError 错误
pymssql.install_as_MySQLdb() 报 AttributeError : ‘module' object has no attribute 'install_as_MySQLdb"rnrnrnpymssql已安装,但在python里执行pymssql.install_as_MySQLdb() 也报上面错误rn
Python中的AttributeError错误的常见原因
常见的原因如下: 类构造函数出了问题,本来是init()函数,但有几个类的构造函数成了_init,少了一个’_’符号 缩进不正确,把空格当做tab。
AttributeError: 'module' object has no attribute 'dumps'
[code=python]rnimport jsonrnd = dict(name='Bob', age=20, score=88)rnjson.dumps(d)rn[/code]rnrn以上代码在命令行输入运行结果是正确的,但是在pycharm中总是报如下错误:rn[code=text]rnTraceback (most recent call last):rn File "/home/zong/PycharmProjects/first/json.py", line 1, in rn import jsonrn File "/home/zong/PycharmProjects/first/json.py", line 3, in rn json.dumps(d)rnAttributeError: 'module' object has no attribute 'dumps'rn[/code]rnrn什么原因?怎么解决?
AttributeError: 'module' object has no attribute 'LWPCookieJar'
[code=python]import cookielibrnrndef test():rn ck = cookielib.LWPCookieJar()rnrntest()[/code]rnrnrn为什么提示如下错误:rnAttributeError: 'module' object has no attribute 'LWPCookieJar'
AttributeError: module 'jieba' has no attribute 'cut' python3.6
AttributeError: module 'jieba' has no attribute 'cut'rnrnpython3.6rnrn这个问题怎么解决。
怎么解决??
数据库怎么和SQL联接..
怎么解决???????????
比如在内存中创建一个800*600的24位位图rn颜色全为白色rn怎么创建?rnrn创建后,在ondraw里面怎么显示出来?rnrn点save 后,然后怎么寸成bmp文件呢?rnrnrn麻烦写一下这三个过程的代码好吗?真的很感谢!因为我要在创建后修改一些像素,所以想这样做。
怎么解决???
LINK : warning LNK4089: all references to "SHELL32.dll" discarded by /OPT:REF
Mouse 2118怎么解决呢,怎么解决
Problem DescriptionrnA greedy mouse cici ate rat poison by mistake. To save herself, she have to drink.rnrnrn![](http://acm.hdu.edu.cn/data/images/C96-1006-1.jpg)rnrnCici can only walk in four ways that marked in the photoes followed and only move in the region that colored blue..She expend energy every step.There are cheese in every position which cici can eat to gain energy once she is there.He will never reach the river if she run out of energy.The initially energy of cici is energy of the cheese at the coordinate (0,0).rnif when the mouse arrive a position has 0 energy , he can't eat the cheese.rnNow can you help the wretched monse to calculate whether can he get to the river.rnIf she can,calculate the minimun energy of the maximal energy of every possible position of the river(Y = N-1).rn rnrnInputrnThere are several test cases.In each case,there are three integers n(0
怎么解决?
java.lang.NoClassDefFoundError: HelloWorldrnrnException in thread "main"
怎么解决
[img=https://img-bbs.csdn.net/upload/201306/06/1370518313_271079.png][/img][img=https://img-bbs.csdn.net/upload/201306/06/1370518321_964386.png][/img][img=https://img-bbs.csdn.net/upload/201306/06/1370518331_123894.png][/img]
怎么解决????
<%rnProvider = "Provider=Microsoft.Jet.OLEDB.4.0;"rnPath = "Data Source=" & Server.MapPath("skwldb/db.mdb")rnSet conn= Server.CreateObject("ADODB.Connection")rnp1=Provider&Pathrnconn.Open P1rnrn%>rn<%rndim visiter 'visiter=访问人数rndim sql 'sqlrndim rsrnsql="select visiter from visiter"rnset rs=conn.execute(sql)rncount=rs("visiter")rnCountLen=len(count)rnfor i=1 to 6-countLenrn response.write ""rnnext rnrnfor i=1 to countlenrn response.write ""rnnext rnsql="update visiter set visiter=visiter+1"rnset rs=conn.execute(sql)rnconn.closernset conn=nothingrn%>rn/////////////rn<%rndb="skwldb/db.mdb"rnSet conn2 = Server.CreateObject("ADODB.Connection")rnconnstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(""&db&"")rnconn2.Open connstrrn%>rn<%sql2="select top 8 * from zhxw order by fbsj desc" rnset rs2=server.createobject("adodb.recordset") rnrs2.open sql2,conn,3 rnif rs2.eof then rnresponse.write "现在尚未有内容!"rnelse rnend ifrn%>rn.....rn<%rnwhile not rs2.eof %>rn.....rn<%=rs2("title")%> [<%=rs2("fbsj")%rn......rn<%rs2.movenext rnwend%>rn <%rs2.close%>rnrnrnrn 以上二个放在一个页面上出错提示rnADODB.Recordset 错误 '800a0e7d' rnrn应用程序要求对象操作,但此对象有一参数调用了一个已关闭的或无效的 Connection 对象。 rnrn怎么解决????
相关热词 c#入门推荐书 c# 解码海康数据流 c# xml的遍历循环 c# 取 查看源码没有的 c#解决高并发 委托 c#日期转化为字符串 c# 显示问号 c# 字典对象池 c#5.0 安装程序 c# 分页算法