Wu Yuxiong - inherently high natural TensorFlow Package: TFLearn processing using data sets achieved MNIST LeNet-5 model

# 1. TFLearn API definitions winder neural network. 

Import tflearn
 Import tflearn.datasets.mnist AS MNIST 

from tflearn.layers.conv Import conv_2d, max_pool_2d
 from tflearn.layers.estimator Import Regression
 from tflearn.layers.core Import Input_Data, Dropout, fully_connected 
 
trainX, trainY, testX, testy = MNIST. load_data (data_dir = " F.: 201806-GitHub \\ \\ \\ TensorFlowGoogle Datasets MNIST_data \\ " , one_hot = True)
 # to resize the image data into a format convolution neural network input. 
= trainX.reshape trainX ([-. 1, 28, 28,. 1 ]) 
testX= testX.reshape([-1, 28, 28, 1])
 
# 构建神经网络。
net = input_data(shape=[None, 28, 28, 1], name='input')
net = conv_2d(net, 32, 5, activation='relu')
net = max_pool_2d(net, 2)
net = conv_2d(net, 64, 5, activation='relu')
net = max_pool_2d(net, 2)
net = fully_connected(net, 500, activation='relu')
net = fully_connected(net, 10, activation='softmax')
# Define learning task. SGD designated optimizer, learning of 0.01, the loss of cross-entropy function. 
Regression = NET (NET, Optimizer = ' SGD ' , learning_rate = 0.01, Loss = ' categorical_crossentropy ' )
# 2. train the neural network by TFLearn the API. 
# A network architecture defined training model, the effect of the model validation and verification on the data specified. 
= tflearn.DNN Model (NET, tensorboard_verbose = 0) 
model.fit (trainX, trainY, n_epoch = 10, validation_set = ([testX, testy]), show_metric = True)

 

Guess you like

Origin www.cnblogs.com/tszr/p/12070148.html