How to do pooling using keras?

How to do pooling using keras?

How to do pooling using keras?

This recipe helps you do pooling using keras


Recipe Objective

How to do pooling using keras?

Pooling is an operation as a layer offered by Keras to be implemented by adding to CNN between layers.

The pooling layer is mainly added after the convolutional layer and it can be repeated after convolutional layers.

Step 1- Importing Libraries

import numpy as np from keras.models import Sequential from keras.layers import Conv2D from keras.layers import AveragePooling2D

Step 2- Making a 2D array

Making a 2d array with an optimal size so that preprocessing can be done easily.

# define input data data = [[0, 1, 2, 3, 4, 5], [6, 7, 8, 9, 10, 11], [0, 0, 15, 14, 13, 12], [0, 0, 16, 17, 18, 0]] data = np.array(data) data = data.reshape(1, 6, 4, 1)

Step 3- Create the CNN model.

Creating a CNN model with required parameters.

# create model model = Sequential() model.add(Conv2D(1, (3,3), activation='relu', input_shape=(8, 8, 1))) model.add(AveragePooling2D())

Step 4- Print the summary of model

# summarize model model.summary()
Model: "sequential"
Layer (type)                 Output Shape              Param #   
conv2d (Conv2D)              (None, 6, 6, 1)           10        
average_pooling2d (AveragePo (None, 3, 3, 1)           0         
Total params: 10
Trainable params: 10
Non-trainable params: 0

Relevant Projects

German Credit Dataset Analysis to Classify Loan Applications
In this data science project, you will work with German credit dataset using classification techniques like Decision Tree, Neural Networks etc to classify loan applications using R.

PySpark Tutorial - Learn to use Apache Spark with Python
PySpark Project-Get a handle on using Python with Spark through this hands-on data processing spark python tutorial.

Deep Learning with Keras in R to Predict Customer Churn
In this deep learning project, we will predict customer churn using Artificial Neural Networks and learn how to model an ANN in R with the keras deep learning package.

Predict Credit Default | Give Me Some Credit Kaggle
In this data science project, you will predict borrowers chance of defaulting on credit loans by building a credit score prediction model.

Predict Macro Economic Trends using Kaggle Financial Dataset
In this machine learning project, you will uncover the predictive value in an uncertain world by using various artificial intelligence, machine learning, advanced regression and feature transformation techniques.

Ensemble Machine Learning Project - All State Insurance Claims Severity Prediction
In this ensemble machine learning project, we will predict what kind of claims an insurance company will get. This is implemented in python using ensemble machine learning algorithms.

Zillow’s Home Value Prediction (Zestimate)
Data Science Project in R -Build a machine learning algorithm to predict the future sale prices of homes.

Resume parsing with Machine learning - NLP with Python OCR and Spacy
In this machine learning resume parser example we use the popular Spacy NLP python library for OCR and text classification.

Mercari Price Suggestion Challenge Data Science Project
Data Science Project in Python- Build a machine learning algorithm that automatically suggests the right product prices.

Identifying Product Bundles from Sales Data Using R Language
In this data science project in R, we are going to talk about subjective segmentation which is a clustering technique to find out product bundles in sales data.