Aidemy 2020/9/30
Hello, it is Yope! I am a liberal arts student, but I was interested in the possibilities of AI, so I went to the AI-specialized school "Aidemy" to study. I would like to share the knowledge gained here with you, and I am summarizing it on Qiita. I am very happy that many people have read the previous summary article. Thank you! This is the first post of deep learning. Nice to meet you.
What to learn this time ・ About deep learning ・ Create a model to classify handwritten numbers
-Deep learning is a type of machine learning that uses a model called deep neural network to classify and regress data. It is called by such a name because it is made with reference to the nerve (neuron) network of living organisms. ・ Deep learning is widely used in the fields of image recognition and voice recognition. The purpose of deep learning is to "improve the recognition accuracy of images and sounds."
-The (deep) neural network is composed of layers of elements that receive and output information called neurons. A model with three or more layers at this time is treated as a model called a deep neural network. At this time, the input layer is called input layer, the output layer is called output layer, and the layer between the two is called hidden layer. The layer in which the previous neuron and the next neuron are connected for each layer is called __fully connected layer __.
-The neuron receives the input values called __input value (x) __ and __ weight parameter (w) __. If the value of the expression represented by x and w is higher than the __threshold (θ) __ of each neuron, the value of 1 is passed to the next neuron, otherwise 0 is passed. This information transmission is called __neuron firing __. ・ In deep learning, a classification model or regression model is created by mechanically adjusting the value of the weight parameter (w).
・ Create a network model → Give the model training data to train → (learning completed) → implement
・ First, as confirmed in the previous section, a network model is constructed by forming a hierarchical structure of some neurons. Next, training data (input value x) is given to the created model and the output value y is output. At first, the value of this y is different from the examination, but the value of the weight parameter (w) is adjusted so that the deviation ΔE from the correct answer data (teacher label) becomes small, and finally the appropriate value is set. The model to be returned is completed.
・ Data preparation → Neural network model construction → Data is given and trained → Model accuracy evaluation
-This time, when the input handwritten data is "7", the value corresponding to "7" among the correct answer labels of the teacher data is 1 (on), and the other values are 0 (off). Data with one correct answer and 0 output other than this is called __one-hot vector __. Also, the assignment (label) when classifying data such as "7" is called __class label __.
-In the case of a handwritten character image, the input data is composed of a set of 28 * 28 numbers (vector). The element that receives and calculates this vector is called __node (unit) __, and the vertical unit group is called __layer (layer) __.
-TensorFlow is a library for machine learning provided by Google. ・ Keras can make TensorFlow code intuitive and concise. Wrapper libraries, like Keras, make it easier to use other libraries (TensorFlow in this case).
-Handwritten digit data can be used immediately by importing a Keras MNIST dataset. ・ (Review) X is image data and y is teacher label data. train is training data and test is test data for model evaluation.
from keras.datasets import mnist
(X_train,y_train),(X_test,y_test)=mnist.load_data()
-The method of building (creating) a model is to first create a __Sequential () __ instance that manages the model, and then create a __Sequential () __ instance. __add (Dense (number of output units in the first fully connected layer, input_dim = number of input units)) __ The input layer and the first fully connected layer are created by using. In addition, it is necessary to specify __activation function __ for the output of the fully connected layer. The method is __add (Activation ("function name")) __. If you want to create the second and subsequent input layers, you can specify the Dense value with the add () method each time (input_dim can be specified only once). Finally, set the learning process with the __compile () __ method and complete.
#Module import
from keras.model import Sequential
from keras.layers import Dense,Activation
#Creation of Sequential instance (model management)
model=Sequential()
#Number of input units 28*28=784, 256 output units of the first fully connected layer, activation function sigmoid
model.add(Dense(256,input_dim=784))
model.add(Activation("sigmoid"))
#256 output units of the second fully connected layer, activation function relu
model.add(Dense(128))
model.add(Activation("relu"))
#Number of output units of the third fully connected layer is 10, activation function softmax
model.add(Dense(10))
model.add(Activation("softmax"))
#Learning process settings (arguments are OK now I don't know)
model.compile(optimizer="sgd",loss="categorical_crossentropy",metrics=["accuracy"])
-Learning with __model.fit (X_train, y_train, verbose = 0or1, epochs = number of learnings) __. ・ If epochs is 1, the progress of learning is output, and if it is 0, it is not output. ・ (Review) Learning is performed by changing the weight so that the difference between the output and the teacher data becomes small.
-Evaluate whether the model can produce high accuracy other than training data by using test data. The accuracy of the test data at this time is called __generalization accuracy __. -Calculate the generalization accuracy with __model.evaluate (X_test, y_test, verbose = 0or1) __.
・ Perform a classification problem using the learned (+ evaluated) model. ・ __Model.predict (self, input data, batch_size = integer, verbose = 0 or1, steps = number of steps) __ ・ About each argument
Regarding the return value, the predict () method returns a NumPy array that stores the predicted values, but since the handwritten character class is 10-dimensional, the largest value is extracted. The method uses __np.argmax (data using predict (), axis = 1) __ to get the index number of the maximum value. Since the index for each row can be obtained by setting axis = 1, only the prediction result is displayed.
-Deep learning refers to classifying and regressing data using a model called __deep neural network __. ・ In deep learning, a classification model or regression model is created by mechanically adjusting the value of the weight parameter (w). ・ The flow of deep learning is data preparation, model creation, model learning, model evaluation, and model classification. -Handwritten digit data can be used immediately by importing a Keras MNIST dataset. -Model creation, model learning, and model evaluation are performed with __add (), fit (), and evaluate () __, respectively. -Classification by model is done by __predict () __, but when actually outputting, use __np.argmax () __.
This time is over. Thank you for reading until the end.
Recommended Posts