Mastering TensorFlow 1.x
上QQ阅读APP看书,第一时间看更新

Creating the TFLearn Layers

Let us learn how to create the layers of the neural network models in TFLearn:

  1. Create an input layer first:
input_layer = tflearn.input_data(shape=[None,num_inputs]
  1. Pass the input object to create further layers:
layer1 = tflearn.fully_connected(input_layer,10,
activation='relu')
layer2 = tflearn.fully_connected(layer1,10,
activation='relu')
  1. Add the output layer:
output = tflearn.fully_connected(layer2,n_classes,
activation='softmax')
  1. Create the final net from the estimator layer such as regression:
net = tflearn.regression(output,
optimizer='adam',
metric=tflearn.metrics.Accuracy(),
loss='categorical_crossentropy'
)

The TFLearn provides several classes for layers that are described in following sub-sections.