日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

TF之GD:基于tensorflow框架搭建GD算法利用Fashion-MNIST数据集实现多分类预测(92%)

發布時間:2025/3/21 编程问答 16 豆豆
生活随笔 收集整理的這篇文章主要介紹了 TF之GD:基于tensorflow框架搭建GD算法利用Fashion-MNIST数据集实现多分类预测(92%) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

TF之GD:基于tensorflow框架搭建GD算法利用Fashion-MNIST數據集實現多分類預測(92%)

?

?

?

目錄

輸出結果

實現代碼


?

?

?

輸出結果

Successfully downloaded train-images-idx3-ubyte.gz 9912422 bytes. Extracting data/fashion\train-images-idx3-ubyte.gz Successfully downloaded train-labels-idx1-ubyte.gz 28881 bytes. Extracting data/fashion\train-labels-idx1-ubyte.gz Successfully downloaded t10k-images-idx3-ubyte.gz 1648877 bytes. Extracting data/fashion\t10k-images-idx3-ubyte.gz Successfully downloaded t10k-labels-idx1-ubyte.gz 4542 bytes. Extracting data/fashion\t10k-labels-idx1-ubyte.gz(55000, 784) (55000, 10) Epoch: 0,acc: 0.7965 Epoch: 1,acc: 0.8118 Epoch: 2,acc: 0.8743 Epoch: 3,acc: 0.8997 Epoch: 4,acc: 0.9058 Epoch: 5,acc: 0.9083 Epoch: 6,acc: 0.9102 Epoch: 7,acc: 0.9117 Epoch: 8,acc: 0.9137 Epoch: 9,acc: 0.9147 Epoch: 10,acc: 0.9158 Epoch: 11,acc: 0.9166 Epoch: 12,acc: 0.9186 Epoch: 13,acc: 0.9191 Epoch: 14,acc: 0.9187 Epoch: 15,acc: 0.9195 Epoch: 16,acc: 0.9206 Epoch: 17,acc: 0.9207 Epoch: 18,acc: 0.9216 Epoch: 19,acc: 0.9215 Epoch: 20,acc: 0.9218

?

實現代碼

#TF之GD:基于tensorflow框架搭建GD算法利用Fashion-MNIST數據集實現多分類預測(92%) import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_datafashion = input_data.read_data_sets('data/fashion', one_hot=True)print(fashion.train.images.shape) print(fashion.train.labels.shape)batch_size = 100 batch_num = fashion.train.num_examples // batch_size#定義X,Y參數 x = tf.placeholder(tf.float32, shape=[None, 784]) y = tf.placeholder(tf.float32, shape=[None, 10]) #定義W,B參數 W = tf.Variable(tf.truncated_normal([784, 10], stddev= 0.1)) b = tf.Variable(tf.zeros([10]) + 0.1)#預測結果 prediction = tf.nn.softmax(tf.matmul(x, W) + b) #使用交叉熵計算loss cross_entropy = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits_v2(logits=prediction, labels=y)) #定義優化器 train_step = tf.train.GradientDescentOptimizer(0.2).minimize(cross_entropy) #判斷預測結果是否正確 correct_prediction = tf.equal(tf.argmax(prediction, 1), tf.argmax(y, 1)) #計算準確率,將bool值轉為float32 accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))with tf.Session() as sess:sess.run(tf.global_variables_initializer())for epoch in range(21):for i in range(batch_num):batch_xs, batch_ys = fashion.train.next_batch(batch_size)sess.run(train_step, feed_dict={x: batch_xs, y:batch_ys})acc = sess.run(accuracy, feed_dict={x:fashion.test.images, y:fashion.test.labels})print('Epoch: '+str(epoch)+',acc: '+str(acc))

?

?

?

?

?

?

總結

以上是生活随笔為你收集整理的TF之GD:基于tensorflow框架搭建GD算法利用Fashion-MNIST数据集实现多分类预测(92%)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。