gpt4 book ai didi

python - tensorflow 属性错误initialize_all_variables

转载 作者:行者123 更新时间:2023-11-30 09:00:58 28 4
gpt4 key购买 nike

我是 tensorflow 新手。以下是我尝试运行的程序。

import numpy as np
import tensorflow as tf
with tf.Session() as sess:
x=tf.placeholder("float",[1,3])
relu_out=x
num_layers=2
for layer in range(num_layers):
w=tf.Variable(tf.random_normal([3,3]))
b=tf.Variable(tf.zeros([1,3]))
relu_out=tf.nn.relu(tf.matmul(relu_out,w)+b)
softmax_w=tf.Variable(tf.random_normal([3,3]))
softmax_b=tf.Variable(tf.zeros([1,3]))
logit=tf.matmul(relu_out,softmax_w)+softmax_b
softmax=tf.nn.softmax(logit)
answer=np.array([[0.0,1.0,0.0]])
labels=tf.placeholder("float",[1,3])
cross_entropy=tf.nn.softmax_cross_entropy_with_logits(relu_out,labels,name='xentropy')
optimizer=tf.train.GradientDescentOptimizer(0.1)
train_op=optimizer.minimize(cross_entropy)
sess.run(tf.initialize_all_vraiables())
for step in range(10):
sess.run(train_op,feed_dict={x:np.array([[1.0,2.0,3.0]]),labels:answer})

显示以下错误:

Traceback (most recent call last):
File "/home/nilay/gdrive/REU/summer_exp/tf_tut/tf_add_layers.py", line 20, in <module>
sess.run(tf.initialize_all_vraiables())
AttributeError: 'module' object has no attribute 'initialize_all_vraiables'

请帮我解决这个问题。

最佳答案

您的代码中有一个拼写错误:

是 tf.initialize_all_变量 不是 tf.initialize_all_vraiables

关于python - tensorflow 属性错误initialize_all_variables,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37619904/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com