tensorflow属性错误initialize_all_variables

时间:2016-06-03 17:03:04

标签: python machine-learning neural-network tensorflow

我是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'

请帮我解决。

1 个答案:

答案 0 :(得分:2)

您的代码中存在拼写错误:

是tf.initialize_all_ 变量而不是tf.initialize_all_ vraiables