First initialize the input data X, create layer 1 and calculate the activation value a1, create layer 2 and calculate the activation value a2, which is an explicit form of the forward propagation code.
Another, simpler way to create a neural network
Creating layer 1 and layer 2 is the same as the previous method, but we don't need to manually get the activation value and pass it to the next layer
You can use the sequential function Sequential() to concatenate layer 1 and layer 2 in sequence and create a neural network.
If you want to train this neural network, you need the model.compile() and model.fit() functions, which will be discussed later
If you need to predict new examples, you can use the model.predict() function, which can directly output the corresponding activation value a2, without manually performing calculations layer by layer.
We will try to classify digits by layer 1, 2, 3, when using this new way of encoding, we can use the sequential() function to concatenate these three layers in sequence and create a new neural network. Afterwards, you can store the data set in the X, Y matrix, and run the model.compile() compilation function, and then run the model, fit() fitting function to train on the data set X, Y. Finally, the model.predict() prediction function can be used to make predictions for new examples.
Easier, more compact way to create neural networks
Generally speaking, we do not explicitly define layer 1, 2, and 3, that is, clearly define layer 1, 2, and 3. It will only be defined that this is a model of several layers concatenated together in sequence. More, we just put the layers directly into the sequential() sequence function.
The difference between it and the previous two methods is that through the sequential() sequence function, directly tell Tensorflow to create a neural network model for me, and connect the three layers together in sequence. The rest of the code is the same as before.