FMUSER Wirless Transmit Video And Audio More Easier !

[email protected] WhatsApp +8618078869184
Language

    [Continued] Depth Learning Note 13: Tensorflow actual combat handwritten Mnist handwritten digital identification

     

    The last talk of the author learned how to build a convolutional neural network model using Tensorflow. This section we will continue to use Tensorflow's convenience to complete the identification of Mnist handwritten digital data sets. The mnist dataset is a data set for the study of a research depth study based on the American National Standard Technology Research Institute. Mnist consists of 70,000 different people handwritten 0-9 10 numbers of grayscale graphs. This section is to study how to build a CNN model with Tensorflow to identify these handwritten numbers. Data Import Mnist As a standard depth learning dataset, there is a package in a large depth learning open source framework. So we can import related modules directly from Tensorflow: import tensorflow as tffrom tensorflow.examples.tutorials.mnist import input_data # load mnist datamnist = input_data.read_data_sets ( 'MNIST_data', one_hot = True) to quickly build up a simple neural network After the model data is imported, you can create the corresponding Tensor variable according to Tensorflow's paradigm and create a session: # create the sessionSESS = TF.INTERACTINESESSESS = TF.INTERACTINESESSESS = TF.INTERACTIVESession () # Create Variables and Run the sessionX = TF.PLACEHOLDER ('float', shape = [NONE, 784]) Y_= Tf.PlaceHolder ('Float', Shape = [None, 10]) W = tf.variable (tf.zeros ([784, 10]))) B = tf.variable (tf.zeros ([10])) Sess.Run (tf.global_variables_initializer ()) Defines the forward propagation process and loss functions: # defineThenetandLossFunctionY = Tf.nn.softmax (tf.matmul (x, w) + b) Cross_entropy = -tf.reduce_sum (y_* tf.log (y)) Model Training: # train the modeltrain_step = tf.train.gradientDescentOptimizer (0.01) .minimize (cross_entropy) for i in inheng (1000): BATCH = mnist.train.next_batch (50) Train_step.run (feed_dict = {x: BATCH [0], y_: batch [1]}) Prediction of test sets using training: # Evaluate the modelcorRect_prediction = tf.equal (tf.argmax (y, 1) , tf.argmax (y_, 1)) Accuracy = tf.reduce_mean (tf.cast (Correct_Prediction, "Float")) PRINT (confuracy.eval (feed_dict = {x: mnist.test.temages, y_: mnist.test.labels}) The prediction accuracy is 0.9, although it is also a high accuracy, but for the mnist Data sets, such results have great improvement space. So we continue to optimize the model structure and add a convolutional structure for the model. Building a convolutional neural network model Definition initialization model weight function: # itIlize the weightdef 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) Defines Convolution and Pool Chemicals: # convolutional and poolingdef conv2d (x, w): return tf.nn.conv2d (x, w, stride = [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') Built the first layer convolution: # The first convolution layerw_conv1 = weight_variable ([5, 5, 1, 32]) B_Conv1 = BIAS_VARIABLE ([32]) X_Image = tf.reshape (x, [-1, 28, 28, 1]) h_conv1 = tf.nn.relu (conv2d (x_image, w_conv1) + b_conv1) H_Pool1 = max_pool_2x2 (h_conv1) Built a second layer convolution: # the second convolution layerw_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) Built a full connection layer: # dense layer / full_connected layerw_fc1 = weightt_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) Set Dropout to prevent over-fitting: # dropout to prevent overfittingkeep_prob = tf.PlaceHolder ("float") H_fc1_drop = tf.nn.dropout (H_FC1, Keep_PROB) Defines the output layer SoftMax: # modpter outputw_fc2 = weight = weight_variable ([1024, 10]) B_FC2 = BIAS_VARIABLE ([10]) y_conv = tf.nn.softmax (tf.matmul (h_fc1_drop, w_fc2) + b_fc2) training model and predicts: # model trainning and evatatingcross_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 ince (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_accurac ") 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})) Some iterative processes and forecast results are as follows: After adding two layers of convolution, our model predictive accuracy reached 0.9931, model training It is better, read the full story

     

     

     

     

    List all Question

    Nickname

    Email

    Questions

    Our other product:

    Professional FM Radio Station Equipment Package

     



     

    Hotel IPTV Solution

     


      Enter email  to get a surprise

      fmuser.org

      es.fmuser.org
      it.fmuser.org
      fr.fmuser.org
      de.fmuser.org
      af.fmuser.org ->Afrikaans
      sq.fmuser.org ->Albanian
      ar.fmuser.org ->Arabic
      hy.fmuser.org ->Armenian
      az.fmuser.org ->Azerbaijani
      eu.fmuser.org ->Basque
      be.fmuser.org ->Belarusian
      bg.fmuser.org ->Bulgarian
      ca.fmuser.org ->Catalan
      zh-CN.fmuser.org ->Chinese (Simplified)
      zh-TW.fmuser.org ->Chinese (Traditional)
      hr.fmuser.org ->Croatian
      cs.fmuser.org ->Czech
      da.fmuser.org ->Danish
      nl.fmuser.org ->Dutch
      et.fmuser.org ->Estonian
      tl.fmuser.org ->Filipino
      fi.fmuser.org ->Finnish
      fr.fmuser.org ->French
      gl.fmuser.org ->Galician
      ka.fmuser.org ->Georgian
      de.fmuser.org ->German
      el.fmuser.org ->Greek
      ht.fmuser.org ->Haitian Creole
      iw.fmuser.org ->Hebrew
      hi.fmuser.org ->Hindi
      hu.fmuser.org ->Hungarian
      is.fmuser.org ->Icelandic
      id.fmuser.org ->Indonesian
      ga.fmuser.org ->Irish
      it.fmuser.org ->Italian
      ja.fmuser.org ->Japanese
      ko.fmuser.org ->Korean
      lv.fmuser.org ->Latvian
      lt.fmuser.org ->Lithuanian
      mk.fmuser.org ->Macedonian
      ms.fmuser.org ->Malay
      mt.fmuser.org ->Maltese
      no.fmuser.org ->Norwegian
      fa.fmuser.org ->Persian
      pl.fmuser.org ->Polish
      pt.fmuser.org ->Portuguese
      ro.fmuser.org ->Romanian
      ru.fmuser.org ->Russian
      sr.fmuser.org ->Serbian
      sk.fmuser.org ->Slovak
      sl.fmuser.org ->Slovenian
      es.fmuser.org ->Spanish
      sw.fmuser.org ->Swahili
      sv.fmuser.org ->Swedish
      th.fmuser.org ->Thai
      tr.fmuser.org ->Turkish
      uk.fmuser.org ->Ukrainian
      ur.fmuser.org ->Urdu
      vi.fmuser.org ->Vietnamese
      cy.fmuser.org ->Welsh
      yi.fmuser.org ->Yiddish

       
  •  

    FMUSER Wirless Transmit Video And Audio More Easier !

  • Contact

    Address:
    No.305 Room HuiLan Building No.273 Huanpu Road Guangzhou China 510620

    E-mail:
    [email protected]

    Tel / WhatApps:
    +8618078869184

  • Categories

  • Newsletter

    FIRST OR FULL NAME

    E-mail

  • paypal solution  Western UnionBank OF China
    E-mail:[email protected]   WhatsApp:+8618078869184   Skype:sky198710021 Chat with me
    Copyright 2006-2020 Powered By www.fmuser.org

    Contact Us