tensorflow没有这个参数_TensorFlow:训练时参数不更新

我正在使用TensorFlow实现一个分类模型

我面临的问题是,当我运行训练步骤时,我的权重和错误没有得到更新。结果,我的网络一直返回相同的结果。在

我根据TensorFlow网站上的MNIST example开发了我的模型。在import numpy as np

import tensorflow as tf

sess = tf.InteractiveSession()

#load dataset

dataset = np.loadtxt('char8k.txt', dtype='float', comments='#', delimiter=",")

Y = np.asmatrix( dataset[:,0] )

X = np.asmatrix( dataset[:,1:1201] )

m = 11527

labels = 26

# y is update to 11527x26

Yt = np.zeros((m,labels))

for i in range(0,m):

index = Y[0,i] - 1

Yt[i,index]= 1

Y = Yt

Y = np.asmatrix(Y)

#------------------------------------------------------------------------------

#graph settings

x = tf.placeholder(tf.float32, shape=[None, 1200])

y_ = tf.placeholder(tf.float32, shape=[None, 26])

Wtest = tf.Variable(tf.truncated_normal([1200,26], stddev=0.001))

W = tf.Variable(tf.truncated_normal([1200,26], stddev=0.001))

b = tf.Variable(tf.zeros([26]))

sess.run(tf.initialize_all_variables())

y = tf.nn.softmax(tf.matmul(x,W) + b)

cross_entropy = -tf.reduce_sum(y_*tf.log(y))

train_step = tf.train.GradientDescentOptimizer(0.01).minimize(cross_entropy)

Wtest = W

for i in range(10):

print("iteracao:")

print(i)

Xbatch = X[np.random.randint(X.shape[0],size=100),:]

Ybatch = Y[np.random.randint(Y.shape[0],size=100),:]

train_step.run(feed_dict={x: Xbatch, y_: Ybatch})

print("atualizacao de pesos")

print(Wtest==W)#monitora atualizaçao dos pesos

correct_prediction = tf.equal(tf.argmax(y,1), tf.argmax(y_,1))

accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))

print("precisao:Y")

print accuracy.eval(feed_dict={x: X, y_: Y})

print(" ")

print(" ")

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值