import tensorflow as tf
import numpy as np
from tensorflow.examples.tutorials.mnist import input_data
def initWeights(shape):
return tf.Variable(tf.random_normal(shape, stddev = 0.1))
def initBiases(shape):
return tf.Variable(tf.random_normal(shape, stddev = 0.1))
def model(X, weights, baises):
return tf.matmul(X, weights) + baises
mnist = input_data.read_data_sets(\'E:/bonc_projects/fire_event/mnist_dataset\', one_hot = True)
trX, trY, teX, teY = mnist.train.images, mnist.train.labels, mnist.test.images, mnist.test.labels
X = tf.placeholder(\'float\', [None, 784])
Y = tf.placeholder(\'float\', [None, 10])
learning_rate = 0.05
epcoh = 100
weights = initWeights([784,10])
biases = initBiases([10])
y_ = model(X, weights, biases)
cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(logits=y_, labels=Y))
train_op = tf.train.GradientDescentOptimizer(learning_rate).minimize(cost)
predict_op = tf.argmax(y_, 1)
with tf.Session() as sess:
tf.initialize_all_variables().run()
for i in range(epcoh):
for start, end in zip(range(0, len(trX), 128), range(128, len(trX)+1, 128)):
sess.run(train_op, feed_dict = {X: trX[start:end], Y: trY[start:end]})
print (i, np.mean(np.argmax(teY, axis=1) == sess.run(predict_op, feed_dict={X: teX})))
继续阅读与本文标签相同的文章
上一篇 :
谷歌 AdSense 自动广告新版即将来袭
下一篇 :
社交时代,人人皆老板
-
陆奇:看好5G技术,但应用好5G还需要时间
2026-05-14栏目: 教程
-
在Visual Studio中使用clang-tidy进行代码分析
2026-05-14栏目: 教程
-
甘薇贾跃亭曝出离婚消息,贾跃亭破产前转账51万美元,作为“家庭费用”
2026-05-14栏目: 教程
-
指静脉识别黑科技加身,6.9秒破百,体验纯电动轿跑零跑S01
2026-05-14栏目: 教程
-
首届中国工业互联网大赛在乌镇开赛
2026-05-14栏目: 教程
