成人国产在线小视频_日韩寡妇人妻调教在线播放_色成人www永久在线观看_2018国产精品久久_亚洲欧美高清在线30p_亚洲少妇综合一区_黄色在线播放国产_亚洲另类技巧小说校园_国产主播xx日韩_a级毛片在线免费

資訊專欄INFORMATION COLUMN

在tensorflow上進(jìn)行機(jī)器學(xué)習(xí)的“Hello World”:MNIST 手寫識(shí)別

garfileo / 1063人閱讀

摘要:安裝好了安裝筆記,接下來就在他的官網(wǎng)指導(dǎo)下進(jìn)行手寫數(shù)字識(shí)別實(shí)驗(yàn)。實(shí)驗(yàn)過程進(jìn)入虛擬環(huán)境后,首先進(jìn)入目錄然后進(jìn)入交互終端。

安裝好了tensorflow(TensorFlow 安裝筆記),接下來就在他的官網(wǎng)指導(dǎo)下進(jìn)行Mnist手寫數(shù)字識(shí)別實(shí)驗(yàn)。

softmax 實(shí)驗(yàn)過程

進(jìn)入tfgpu虛擬環(huán)境后,首先進(jìn)入目錄:/anaconda2/envs/tfgpu/lib/python2.7/site-packages/tensorflow/examples/tutorials/mnist/,然后進(jìn)入IPython交互終端。

In [4]: from tensorflow.examples.tutorials.mnist import input_data
   ...: mnist = input_data.read_data_sets("MNIST_data/", one_hot=True)
   ...: 
Successfully downloaded train-images-idx3-ubyte.gz 9912422 bytes.
Extracting MNIST_data/train-images-idx3-ubyte.gz
Successfully downloaded train-labels-idx1-ubyte.gz 28881 bytes.
Extracting MNIST_data/train-labels-idx1-ubyte.gz
Successfully downloaded t10k-images-idx3-ubyte.gz 1648877 bytes.
Extracting MNIST_data/t10k-images-idx3-ubyte.gz
Successfully downloaded t10k-labels-idx1-ubyte.gz 4542 bytes.
Extracting MNIST_data/t10k-labels-idx1-ubyte.gz

In [5]: import tensorflow as tf

In [6]: x = tf.placeholder(tf.float32, [None, 784])

In [7]: W = tf.Variable(tf.zeros([784, 10]))
   ...: b = tf.Variable(tf.zeros([10]))
   ...: 

In [8]: y = tf.nn.softmax(tf.matmul(x, W) + b)

In [9]: y_ = tf.placeholder(tf.float32, [None, 10])

In [10]: cross_entropy = tf.reduce_mean(-tf.reduce_sum(y_ * tf.log(y), reduction_indices=[1]))

In [11]: train_step = tf.train.GradientDescentOptimizer(0.5).minimize(cross_entropy)

In [12]: init = tf.initialize_all_variables()

In [13]: sess = tf.Session()
    ...: sess.run(init)
    ...: 
I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:925] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
I tensorflow/core/common_runtime/gpu/gpu_init.cc:102] Found device 0 with properties: 
name: GeForce 940M
major: 5 minor: 0 memoryClockRate (GHz) 1.124
pciBusID 0000:08:00.0
Total memory: 1023.88MiB
Free memory: 997.54MiB
I tensorflow/core/common_runtime/gpu/gpu_init.cc:126] DMA: 0 
I tensorflow/core/common_runtime/gpu/gpu_init.cc:136] 0:   Y 
I tensorflow/core/common_runtime/gpu/gpu_device.cc:839] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce 940M, pci bus id: 0000:08:00.0)

In [14]: for i in range(1000):
    ...:   batch_xs, batch_ys = mnist.train.next_batch(100)
    ...:   sess.run(train_step, feed_dict={x: batch_xs, y_: batch_ys})
    ...:   

In [15]: correct_prediction = tf.equal(tf.argmax(y,1), tf.argmax(y_,1))

In [16]: accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
    ...: 

In [17]: print(sess.run(accuracy, feed_dict={x: mnist.test.images, y_: mnist.test.labels}))
0.9186
softmax實(shí)驗(yàn)說明
In [4]:主要是下載數(shù)據(jù)

In [6]:意思是先分配輸入x,None即輸入圖片數(shù)量稍后運(yùn)行時(shí)確定,784即28*28,把一張28*28的圖片拉長成為一維向量,保證每張圖片拉長方式相同即可

In [7]:分配權(quán)重w和偏置b

In [8]:實(shí)現(xiàn)softmax模型,獲得輸出判斷值y

In [9]: 分配實(shí)際判斷值y_

In [10]:獲得交叉熵形式的代價(jià)函數(shù)

In [11]:每一步使用0.5的學(xué)習(xí)率(步長)來進(jìn)行梯度下降算法

In [12]:初始化所有變量

In [13]:開啟一個(gè)會(huì)話,啟動(dòng)模型

In [14]:進(jìn)行1000次隨機(jī)梯度下降算法

In [15]:比較輸出判斷值y和真實(shí)判斷值y_

In [16]:獲得準(zhǔn)確率

In [17]:獲得測(cè)試集上的準(zhǔn)確率:91.86%
神經(jīng)網(wǎng)絡(luò)實(shí)驗(yàn)過程
In [1]: from tensorflow.examples.tutorials.mnist import input_data
   ...: mnist = input_data.read_data_sets("MNIST_data", one_hot=True)
   ...: 
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcublas.so locally
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcudnn.so locally
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcufft.so locally
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcuda.so.1 locally
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcurand.so locally
Extracting MNIST_data/train-images-idx3-ubyte.gz
Extracting MNIST_data/train-labels-idx1-ubyte.gz
Extracting MNIST_data/t10k-images-idx3-ubyte.gz
Extracting MNIST_data/t10k-labels-idx1-ubyte.gz

In [2]: import tensorflow as tf
   ...: sess = tf.InteractiveSession()
   ...: 
I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:925] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
I tensorflow/core/common_runtime/gpu/gpu_init.cc:102] Found device 0 with properties: 
name: GeForce 940M
major: 5 minor: 0 memoryClockRate (GHz) 1.124
pciBusID 0000:08:00.0
Total memory: 1023.88MiB
Free memory: 997.54MiB
I tensorflow/core/common_runtime/gpu/gpu_init.cc:126] DMA: 0 
I tensorflow/core/common_runtime/gpu/gpu_init.cc:136] 0:   Y 
I tensorflow/core/common_runtime/gpu/gpu_device.cc:839] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce 940M, pci bus id: 0000:08:00.0)

In [3]: def weight_variable(shape):
   ...:   initial = tf.truncated_normal(shape, stddev=0.1)
   ...:   return tf.Variable(initial)
   ...: 
   ...: def bias_variable(shape):
   ...:   initial = tf.constant(0.1, shape=shape)
   ...:   return tf.Variable(initial)
   ...: 

In [4]: 

In [4]: def conv2d(x, W):
   ...:   return tf.nn.conv2d(x, W, strides=[1, 1, 1, 1], padding="SAME")
   ...: 
   ...: def max_pool_2x2(x):
   ...:   return tf.nn.max_pool(x, ksize=[1, 2, 2, 1],
   ...:                         strides=[1, 2, 2, 1], padding="SAME")
   ...: 

In [5]: W_conv1 = weight_variable([5, 5, 1, 32])
   ...: b_conv1 = bias_variable([32])
   ...: 

In [6]: 

In [7]: x = tf.placeholder(tf.float32, shape=[None, 784])
   ...: y_ = tf.placeholder(tf.float32, shape=[None, 10])
   ...: 

In [8]: x_image = tf.reshape(x, [-1,28,28,1])
   ...: 

In [9]: h_conv1 = tf.nn.relu(conv2d(x_image, W_conv1) + b_conv1)
   ...: h_pool1 = max_pool_2x2(h_conv1)
   ...: 

In [10]: W_conv2 = weight_variable([5, 5, 32, 64])
    ...: b_conv2 = bias_variable([64])
    ...: 
    ...: h_conv2 = tf.nn.relu(conv2d(h_pool1, W_conv2) + b_conv2)
    ...: h_pool2 = max_pool_2x2(h_conv2)
    ...: 

In [11]: W_fc1 = weight_variable([7 * 7 * 64, 1024])
    ...: b_fc1 = bias_variable([1024])
    ...: 
    ...: h_pool2_flat = tf.reshape(h_pool2, [-1, 7*7*64])
    ...: h_fc1 = tf.nn.relu(tf.matmul(h_pool2_flat, W_fc1) + b_fc1)
    ...: 

In [12]: keep_prob = tf.placeholder(tf.float32)
    ...: h_fc1_drop = tf.nn.dropout(h_fc1, keep_prob)
    ...: 

In [13]: W_fc2 = weight_variable([1024, 10])
    ...: b_fc2 = bias_variable([10])
    ...: 
    ...: y_conv=tf.nn.softmax(tf.matmul(h_fc1_drop, W_fc2) + b_fc2)
    ...: 

In [14]: cross_entropy = tf.reduce_mean(-tf.reduce_sum(y_ * tf.log(y_conv), reduction_indices=[1]))
    ...: train_step = tf.train.AdamOptimizer(1e-4).minimize(cross_entropy)
    ...: correct_prediction = tf.equal(tf.argmax(y_conv,1), tf.argmax(y_,1))
    ...: accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
    ...: sess.run(tf.initialize_all_variables())
    ...: for i in range(2000):
    ...:   batch = mnist.train.next_batch(50)
    ...:   if i%100 == 0:
    ...:     train_accuracy = accuracy.eval(feed_dict={
    ...:         x:batch[0], y_: batch[1], keep_prob: 1.0})
    ...:     print("step %d, training accuracy %g"%(i, train_accuracy))
    ...:   train_step.run(feed_dict={x: batch[0], y_: batch[1], keep_prob: 0.5})
    ...: 
    ...: print("test accuracy %g"%accuracy.eval(feed_dict={
    ...:     x: mnist.test.images, y_: mnist.test.labels, keep_prob: 1.0}))
    ...: 
step 0, training accuracy 0.04
step 100, training accuracy 0.86
step 200, training accuracy 0.92
step 300, training accuracy 0.88
step 400, training accuracy 0.96
step 500, training accuracy 0.9
step 600, training accuracy 1
step 700, training accuracy 0.98
step 800, training accuracy 0.92
step 900, training accuracy 0.98
step 1000, training accuracy 0.94
step 1100, training accuracy 0.96
step 1200, training accuracy 1
step 1300, training accuracy 0.98
step 1400, training accuracy 0.94
step 1500, training accuracy 0.96
step 1600, training accuracy 1
step 1700, training accuracy 0.92
step 1800, training accuracy 0.92
step 1900, training accuracy 0.96
I tensorflow/core/common_runtime/bfc_allocator.cc:639] Bin (256):     Total Chunks: 0, Chunks in use: 0 0B allocated for chunks. 0B client-requested for chunks. 0B in use in bin. 0B client-requested in use in bin.
I tensorflow/core/common_runtime/bfc_allocator.cc:639] Bin (512):     Total Chunks: 1, Chunks in use: 0 768B allocated for chunks. 6.4KiB client-requested for chunks. 0B in use in bin. 0B client-requested in use in bin.
I tensorflow/core/common_runtime/bfc_allocator.cc:639] Bin (1024):     Total Chunks: 0, Chunks in use: 0 0B allocated for chunks. 0B client-requested for chunks. 0B in use in bin. 0B client-requested in use in bin.
...
...
...
...
Limit:                   836280320
InUse:                    83845120
MaxInUse:                117678336
NumAllocs:                  246915
MaxAllocSize:             45883392

W tensorflow/core/common_runtime/bfc_allocator.cc:270] *****_******________________________________________________________________________________________
W tensorflow/core/common_runtime/bfc_allocator.cc:271] Ran out of memory trying to allocate 957.03MiB.  See logs for memory state.
W tensorflow/core/framework/op_kernel.cc:936] Resource exhausted: OOM when allocating tensor with shape[10000,28,28,32]
E tensorflow/core/client/tensor_c_api.cc:485] OOM when allocating tensor with shape[10000,28,28,32]
     [[Node: Conv2D = Conv2D[T=DT_FLOAT, data_format="NHWC", padding="SAME", strides=[1, 1, 1, 1], use_cudnn_on_gpu=true, _device="/job:localhost/replica:0/task:0/gpu:0"](Reshape, Variable/read)]]


In [20]: cross_entropy = tf.reduce_mean(-tf.reduce_sum(y_ * tf.log(y_conv), reduction_indices=[1]))
    ...: train_step = tf.train.AdamOptimizer(1e-4).minimize(cross_entropy)
    ...: correct_prediction = tf.equal(tf.argmax(y_conv,1), tf.argmax(y_,1))
    ...: accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
    ...: sess.run(tf.initialize_all_variables())
    ...: for i in range(20000):
    ...:   batch = mnist.train.next_batch(50)
    ...:   if i%100 == 0:
    ...:     train_accuracy = accuracy.eval(feed_dict={
    ...:         x:batch[0], y_: batch[1], keep_prob: 1.0})
    ...:     print("step %d, training accuracy %g"%(i, train_accuracy))
    ...:   train_step.run(feed_dict={x: batch[0], y_: batch[1], keep_prob: 0.5})
    ...: 
    ...: print("test accuracy %g"%accuracy.eval(feed_dict={
    ...:     x: mnist.test.images[0:200,:], y_: mnist.test.labels[0:200,:], keep_prob: 1.0}))
    ...: 
step 0, training accuracy 0.12
step 100, training accuracy 0.78
step 200, training accuracy 0.88
step 300, training accuracy 0.96
step 400, training accuracy 0.9
step 500, training accuracy 0.96
step 600, training accuracy 0.94
step 700, training accuracy 0.92
step 800, training accuracy 0.92
step 900, training accuracy 0.96
step 1000, training accuracy 0.94
step 1100, training accuracy 0.98
step 1200, training accuracy 0.96
step 1300, training accuracy 1
step 1400, training accuracy 0.98
...
...
...
test accuracy 0.995

In [21]: cross_entropy = -tf.reduce_sum(y_*tf.log(y_conv))
...: train_step = tf.train.AdamOptimizer(1e-4).minimize(cross_entropy)
...: correct_prediction = tf.equal(tf.argmax(y_conv,1), tf.argmax(y_,1))
...: accuracy = tf.reduce_mean(tf.cast(correct_prediction, "float"))
...: sess.run(tf.initialize_all_variables())
...: for i in range(20000):
...:   batch = mnist.train.next_batch(50)
...:   if i%100 == 0:
...:     train_accuracy = accuracy.eval(feed_dict={
...:         x:batch[0], y_: batch[1], keep_prob: 1.0})
...:     print "step %d, training accuracy %g"%(i, train_accuracy)
...:   train_step.run(feed_dict={x: batch[0], y_: batch[1], keep_prob: 0.5})
...: 
...: print "test accuracy %g"%accuracy.eval(feed_dict={
...:     x: mnist.test.images[200:400,:], y_: mnist.test.labels[200:400,:], keep_prob: 1.0})
...:     
...: 
step 0, training accuracy 0.12
step 100, training accuracy 0.94
step 200, training accuracy 0.86
step 300, training accuracy 0.96
step 400, training accuracy 0.9
step 500, training accuracy 1
step 600, training accuracy 0.96
step 700, training accuracy 0.88
step 800, training accuracy 1
step 900, training accuracy 0.98
step 1000, training accuracy 0.96
step 1100, training accuracy 0.94
step 1200, training accuracy 0.96
step 1300, training accuracy 0.96
step 1400, training accuracy 0.94
step 1500, training accuracy 0.98
step 1600, training accuracy 0.96
step 1700, training accuracy 0.98
...
...
...
test accuracy 0.975

In [22]: for i in range(20000):
...:   batch = mnist.train.next_batch(50)
...:   if i%100 == 0:
...:     train_accuracy = accuracy.eval(feed_dict={
...:         x:batch[0], y_: batch[1], keep_prob: 1.0})
...:     print "step %d, training accuracy %g"%(i, train_accuracy)
...:   train_step.run(feed_dict={x: batch[0], y_: batch[1], keep_prob: 0.5})
...: 
...: print "test accuracy %g"%accuracy.eval(feed_dict={
...:     x: mnist.test.images[400:1000,:], y_: mnist.test.labels[400:1000,:], keep_prob: 1.0})
...: 
step 0, training accuracy 1
step 100, training accuracy 1
step 200, training accuracy 0.98
step 300, training accuracy 0.98
step 400, training accuracy 0.98
step 500, training accuracy 1
step 600, training accuracy 0.96
step 700, training accuracy 0.96
...
...
...
test accuracy  0.983333
神經(jīng)網(wǎng)絡(luò)實(shí)驗(yàn)說明
In [1]: 導(dǎo)入數(shù)據(jù),即測(cè)試集和驗(yàn)證集

In [2]: 引入 tensorflow 啟動(dòng)InteractiveSession(比session更靈活)

In [3]: 定義兩個(gè)初始化w和b的函數(shù),方便后續(xù)操作

In [4]: 定義卷積和池化函數(shù),這里卷積采用padding,使得輸入輸出圖像一樣大,池化采取2x2,那么就是4格變一格

In [5]: 定義第一層卷積的w和b

In [7]: 分配輸入x和y_

In [8]: 修改x的shape

In [9]: 把x_image和w進(jìn)行卷積,加上b,然后應(yīng)用ReLU激活函數(shù),最后進(jìn)行max-pooling

In [10]: 第二層卷積,和第一層卷積類似

In [11]: 全連接層

In [12]: 為了減少過擬合,可以在輸出層之前加入dropout。(但是本例子比較簡單,即使不加,影響也不大)

In [13]: 由一個(gè)softmax層來得到輸出

In [14]: 定義代價(jià)函數(shù),訓(xùn)練步驟,用ADAM來進(jìn)行優(yōu)化,可以看出,最后測(cè)試集太大了,我得顯存不夠    

In [20]: 只使用1~200個(gè)圖片作為測(cè)試集,正確率是 0.995

In [21]: 只使用201~400個(gè)圖片作為測(cè)試集,正確率是 0.975

In [22]: 只使用401~1000個(gè)圖片作為測(cè)試集,正確率是 0.983333

這個(gè)CNN的結(jié)構(gòu)如下圖所示:

修改CNN

現(xiàn)在嘗試修改這個(gè)CNN結(jié)構(gòu),增加特征數(shù)量以期獲得更好的效果,修改后的CNN結(jié)構(gòu)如圖:

實(shí)驗(yàn)過程如下:

In [23]:     def weight_variable(shape):
    ...:       initial = tf.truncated_normal(shape, stddev=0.1)
    ...:       return tf.Variable(initial)
    ...:     
    ...:     def bias_variable(shape):
    ...:       initial = tf.constant(0.1, shape=shape)
    ...:       return tf.Variable(initial)
    ...:     def conv2d(x, W):
    ...:       return tf.nn.conv2d(x, W, strides=[1, 1, 1, 1], padding="SAME")
    ...:     def max_pool_2x2(x):
    ...:       return tf.nn.max_pool(x, ksize=[1, 2, 2, 1],
    ...:                             strides=[1, 2, 2, 1], padding="SAME")
    ...:     W_conv1 = weight_variable([5, 5, 1, 64])
    ...:     b_conv1 = bias_variable([64])
    ...:     h_conv1 = tf.nn.relu(conv2d(x_image, W_conv1) + b_conv1)
    ...:     h_pool1 = max_pool_2x2(h_conv1)
    ...:     W_conv2 = weight_variable([5, 5, 64, 128])
    ...:     b_conv2 = bias_variable([128])
    ...:     
    ...:     h_conv2 = tf.nn.relu(conv2d(h_pool1, W_conv2) + b_conv2)
    ...:     h_pool2 = max_pool_2x2(h_conv2)
    ...:     W_fc1 = weight_variable([7 * 7 * 128, 1024])
    ...:     b_fc1 = bias_variable([1024])
    ...:     
    ...:     h_pool2_flat = tf.reshape(h_pool2, [-1, 7*7*128])
    ...:     h_fc1 = tf.nn.relu(tf.matmul(h_pool2_flat, W_fc1) + b_fc1)
    ...:     keep_prob = tf.placeholder("float")
    ...:     h_fc1_drop = tf.nn.dropout(h_fc1, keep_prob)
    ...:     W_fc2 = weight_variable([1024, 10])
    ...:     b_fc2 = bias_variable([10])
    ...:     
    ...:     y_conv=tf.nn.softmax(tf.matmul(h_fc1_drop, W_fc2) + b_fc2)
    ...:     cross_entropy = -tf.reduce_sum(y_*tf.log(y_conv))
    ...:     train_step = tf.train.AdamOptimizer(1e-4).minimize(cross_entropy)
    ...:     correct_prediction = tf.equal(tf.argmax(y_conv,1), tf.argmax(y_,1))
    ...:     accuracy = tf.reduce_mean(tf.cast(correct_prediction, "float"))
    ...:     sess.run(tf.initialize_all_variables())
    ...:     for i in range(20000):
    ...:       batch = mnist.train.next_batch(50)
    ...:       if i%100 == 0:
    ...:         train_accuracy = accuracy.eval(feed_dict={
    ...:             x:batch[0], y_: batch[1], keep_prob: 1.0})
    ...:         print "step %d, training accuracy %g"%(i, train_accuracy)
    ...:       train_step.run(feed_dict={x: batch[0], y_: batch[1], keep_prob: 0.5})
    ...:     
    ...:     print "test accuracy %g"%accuracy.eval(feed_dict={
    ...:         x: mnist.test.images[0:200,:], y_: mnist.test.labels[0:200,:], keep_prob: 1.0})
    ...: 
    ...
    ...
    ...
    test accuracy 1
In [24]: for i in range(20000):
    ...:    batch = mnist.train.next_batch(50)
    ...:    if i%100 == 0:
    ...:       train_accuracy = accuracy.eval(feed_dict={
    ...:          x:batch[0], y_: batch[1], keep_prob: 1.0})
    ...:       print "step %d, training accuracy %g"%(i, train_accuracy)
    ...:    train_step.run(feed_dict={x: batch[0], y_: batch[1], keep_prob: 0.5})
    ...: 
    ...: print "test accuracy %g"%accuracy.eval(feed_dict={x: mnist.test.images[200:400,:], y_: mnist.test.labels[200:400,:], keep_prob: 1.0})
    ...: 
    ...
    ...
    ...
    test accuracy 0.975
In [25]: for i in range(20000):
    ...:    batch = mnist.train.next_batch(50)
    ...:    if i%100 == 0:
    ...:       train_accuracy = accuracy.eval(feed_dict={
    ...:          x:batch[0], y_: batch[1], keep_prob: 1.0})
    ...:       print "step %d, training accuracy %g"%(i, train_accuracy)
    ...:    train_step.run(feed_dict={x: batch[0], y_: batch[1], keep_prob: 0.5})
    ...: 
    ...: print "test accuracy %g"%accuracy.eval(feed_dict={x: mnist.test.images[400:1000,:], y_: mnist.test.labels[400:1000,:], keep_prob: 1.0})
    ...: 
    ...
    ...
    ...
    W tensorflow/core/common_runtime/bfc_allocator.cc:213] Ran out of memory trying to allocate 717.77MiB. The caller indicates that this is not a failure, but may mean that there could be performance gains if more memory is available.
In [26]: print "test accuracy %g"%accuracy.eval(feed_dict={x: mnist.test.images[400:600,:], y_: mnist.test.labels[400:600,:], keep_prob: 1.0})
    ...:
    test accuracy 0.985
In [28]: print "test accuracy %g"%accuracy.eval(feed_dict={x: mnist.test.images[600:800,:], y_: mnist.test.labels[600:800,:], keep_prob: 1.0})
    ...: 
    ...: 
    ...: 
test accuracy 0.985
In [29]: print "test accuracy %g"%accuracy.eval(feed_dict={x: mnist.test.images[800:1000,:], y_: mnist.test.labels[800:1000,:], keep_prob: 1.0})
    ...: 
    ...: 
test accuracy 0.995

修改前的平均準(zhǔn)確率是:

( 0.995*2 + 0.975*2 + 0.9833*6 )/ 10 = 0.98398

修改后的平均準(zhǔn)確率是:

(1*2 + 0.975*2+ 0.985*4 + 0.995*2)/ 10 = 0.98800

可以看出增加特征過后,準(zhǔn)確率提高了,但是內(nèi)存消耗也變大了(400~1000的圖片驗(yàn)證出現(xiàn)了OOM錯(cuò)誤),而且實(shí)驗(yàn)過程中也感受到時(shí)間消耗更大,怎么取舍就取決于具體需求和具體的硬件配置了。

文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請(qǐng)注明本文地址:http://systransis.cn/yun/38131.html

相關(guān)文章

  • 初學(xué)者怎么選擇神經(jīng)網(wǎng)絡(luò)環(huán)境?對(duì)比MATLAB、Torch和TensorFlow

    摘要:本報(bào)告面向的讀者是想要進(jìn)入機(jī)器學(xué)習(xí)領(lǐng)域的學(xué)生和正在尋找新框架的專家。其輸入需要重塑為包含個(gè)元素的一維向量以滿足神經(jīng)網(wǎng)絡(luò)。卷積神經(jīng)網(wǎng)絡(luò)目前代表著用于圖像分類任務(wù)的較先進(jìn)算法,并構(gòu)成了深度學(xué)習(xí)中的主要架構(gòu)。 初學(xué)者在學(xué)習(xí)神經(jīng)網(wǎng)絡(luò)的時(shí)候往往會(huì)有不知道從何處入手的困難,甚至可能不知道選擇什么工具入手才合適。近日,來自意大利的四位研究者發(fā)布了一篇題為《神經(jīng)網(wǎng)絡(luò)初學(xué)者:在 MATLAB、Torch 和 ...

    yunhao 評(píng)論0 收藏0
  • TensorFlow 2.0 / TF2.0 入門教程實(shí)戰(zhàn)案例

    摘要:七強(qiáng)化學(xué)習(xí)玩轉(zhuǎn)介紹了使用創(chuàng)建來玩游戲?qū)⑦B續(xù)的狀態(tài)離散化。包括輸入輸出獨(dú)熱編碼與損失函數(shù),以及正確率的驗(yàn)證。 用最白話的語言,講解機(jī)器學(xué)習(xí)、神經(jīng)網(wǎng)絡(luò)與深度學(xué)習(xí)示例基于 TensorFlow 1.4 和 TensorFlow 2.0 實(shí)現(xiàn) 中文文檔 TensorFlow 2 / 2.0 官方文檔中文版 知乎專欄 歡迎關(guān)注我的知乎專欄 https://zhuanlan.zhihu.com/...

    whataa 評(píng)論0 收藏0

發(fā)表評(píng)論

0條評(píng)論

最新活動(dòng)
閱讀需要支付1元查看
<