from tensorflow.examples.tutorials.mnist import input_data
import tensorflow as tf
mnist = input_data.read_data_sets("MNIST_data/",one_hot=True)
sess = tf.InteractiveSession()
in_units = 784
h1_units = 300
W1 = tf.Variable(tf.truncated_normal([in_units,h1_units],stddev=0.1))
b1 = tf.Variable(tf.zeros([h1_units]))
W2 = tf.Variable(tf.zeros([h1_units,10]))
b2 = tf.Variable(tf.zeros([10]))
x = tf.placeholder(tf.float32,[None,in_units])
keep_prob = tf.placeholder(tf.float32)
hidden1 = tf.nn.relu(tf.matmul(x.W1) + b1)
hidden1_drop = tf.nn.dropout(hidden1,keep_prob)
y = tf.nn.softmax(tf.matmul(hidden1_drop,W2) + b2)
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.AdagradOptimizer(0.3).minimize(cross_entropy)
错误是:
AttributeError Traceback (most recent call last)<ipython-input-15-4dc09f3b4dcf> in <module>()----> 1 hidden1 = tf.nn.relu(tf.matmul(x.W1) + b1) 2 hidden1_drop = tf.nn.dropout(hidden1,keep_prob) 3 y = tf.nn.softmax(tf.matmul(hidden1_drop,W2) + b2) 4 y_ = tf.placeholder(tf.float32,[None,10]) 5 cross_entropy = tf.reduce_mean(-tf.reduce_sum(y_ * tf.log(y),AttributeError: 'Tensor' object has no attribute 'W1'
import tensorflow as tf
mnist = input_data.read_data_sets("MNIST_data/",one_hot=True)
sess = tf.InteractiveSession()
in_units = 784
h1_units = 300
W1 = tf.Variable(tf.truncated_normal([in_units,h1_units],stddev=0.1))
b1 = tf.Variable(tf.zeros([h1_units]))
W2 = tf.Variable(tf.zeros([h1_units,10]))
b2 = tf.Variable(tf.zeros([10]))
x = tf.placeholder(tf.float32,[None,in_units])
keep_prob = tf.placeholder(tf.float32)
hidden1 = tf.nn.relu(tf.matmul(x.W1) + b1)
hidden1_drop = tf.nn.dropout(hidden1,keep_prob)
y = tf.nn.softmax(tf.matmul(hidden1_drop,W2) + b2)
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.AdagradOptimizer(0.3).minimize(cross_entropy)
错误是:
AttributeError Traceback (most recent call last)<ipython-input-15-4dc09f3b4dcf> in <module>()----> 1 hidden1 = tf.nn.relu(tf.matmul(x.W1) + b1) 2 hidden1_drop = tf.nn.dropout(hidden1,keep_prob) 3 y = tf.nn.softmax(tf.matmul(hidden1_drop,W2) + b2) 4 y_ = tf.placeholder(tf.float32,[None,10]) 5 cross_entropy = tf.reduce_mean(-tf.reduce_sum(y_ * tf.log(y),AttributeError: 'Tensor' object has no attribute 'W1'