1 Star 2 Fork 0

laoyinbi / tensorflow-simple-captcha

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
train.py 991 Bytes
一键复制 编辑 原始数据 按行查看 历史
洋子 提交于 2017-12-03 12:22 . 增加文件
import tensorflow as tf
from data import train_images, train_labels, test_labels, test_images
DLEN = len(train_images.data[0])
DNUM = len(train_images.data)
x = tf.placeholder(tf.float32, [None, DLEN])
W = tf.Variable(tf.zeros([DLEN, 10]))
b = tf.Variable(tf.zeros([10]))
y = tf.nn.softmax(tf.matmul(x, W) + b)
y_ = tf.placeholder("float", [None, 10])
cross_entropy = -tf.reduce_sum(y_*tf.log(y))
train_step = tf.train.GradientDescentOptimizer(0.001).minimize(cross_entropy)
saver = tf.train.Saver()
sess = tf.Session()
sess.run(tf.global_variables_initializer())
for i in range(DNUM):
batch_xs = [train_images.data[i]]
batch_ys = [train_labels.data[i]]
sess.run(train_step, feed_dict={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, "float"))
print(sess.run(accuracy, feed_dict={x: test_images.data, y_: test_labels.data}))
saver.save(sess, 'model/model')
sess.close()
1
https://gitee.com/laoyinbi123/tensorflow-simple-captcha.git
git@gitee.com:laoyinbi123/tensorflow-simple-captcha.git
laoyinbi123
tensorflow-simple-captcha
tensorflow-simple-captcha
master

搜索帮助