AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
Nn sequential cnn8/18/2023 If padding is set to same then that means we require the same output spatial dimensions as input. We specify some parameters, 32 represents the number of output feature maps, (3, 3) is the kernel size, our input shape is 32x32 with 3 channels (RGB). Line 7 Our first layer will be a convolution layer. Essentially creates an "empty template" of our model compile( loss = 'categorical_crossentropy',Ģ9 optimizer = SGD( momentum = 0.5, decay = 0.0004, metrics =)) add( Dense( 10, activation = 'softmax'))Ģ7 #Few simple configurations 28 model. add( Dropout( 0.3))Ģ4 #Finally the output dense layer with 10 hidden units corresponding to 25 #our 10 classe 26 model. add( Dense( 512, activation = 'relu'))Ģ2 #this time we set 30% of the nodes to 0 to minimize overfitting 23 model. add( Flatten())Ģ0 #Dense layer with 512 hidden units 21 model. add( MaxPooling2D( pool_size =( 2, 2)))ġ7 #In a convolution NN, we neet to flatten our data before we can 18 #input it into the ouput/dense layer 19 model. add( Conv2D( 32, ( 3, 3), activation = 'relu', padding = 'valid'))ġ5 #maxpool with a kernet of 2x2 16 model. add( Dropout( 0.2))ġ1 #now we add another convolution layer, again with a 3x3 kernel 12 #This time our padding=valid this means that the output dimension can 13 #take any form 14 model. The kernel size is going to be 4 #3x3 and we specify our input shape to be 32x32 with 3 channels 5 #Padding=same means we want the same dimensional output as input 6 #activation specifies the activation function 7 model. Now we can build our CNN model for training!ġ #Now we can go ahead and create our Convolution model 2 model = Sequential()ģ #We want to output 32 features maps. The airplane data would be Building the CNN Model For example, if our third class is airplanes then the one hot vector for Since we have 10 classes our array will be of lenght 10. A one hot vector is an array of 0s and 1s. Line 8 This is our training labels and test labels. Since they represent colour images, we can divide by 255.Īstype converts the integers into floats. Line 4 Takes our training data and our test data and normalises them. astype( 'float32') / 255.0 5 #Then we convert the y values into one-hot vectors 6 #The cifar10 has only 10 classes, thats is why we specify a one-hot 7 #vector of width/class 10 8 y, y_test = u. Here are the required imports for CNN:ġ #Keep in mind the images are in RGB 2 #So we can normalise the data by diving by 255 3 #The data is in integers therefore we need to convert them to float first 4 X, X_test = X. Implementation ImportsĮvery Machine learning heavy Python program starts off by imports. In more technical terms, Keras is a high-level neural network API written in Python. It simply runs atop Tensorflow/Theano, cutting down on the coding and increasing efficiency. So what exactly is Keras? Let's put it this way, it makes programming machine learning algorithms much much easier. Note: For learners who are unaware how Convolutional Neural Newtworks work, here are some excellent links onĪs I did in my previous tutorial I will start by talking about Keras, you can skip it and go straight to the implementatation
0 Comments
Read More
Leave a Reply. |