How to do upsampling and down sampling using keras?
MACHINE LEARNING RECIPES DATA CLEANING PYTHON DATA MUNGING PANDAS CHEATSHEET     ALL TAGS

How to do upsampling and down sampling using keras?

How to do upsampling and down sampling using keras?

This recipe helps you do upsampling and down sampling using keras

0

Recipe Objective

Explaining UpSampling and DownSampling using keras. In UpSampling we insert the null-values between original values to increase the sampling rate. This process is also called Zero - stuffing. The Upsampling creates a layer with no weights it doubles the dimensions of input and so that it can be used in the generation of the model to be followed by a traditional convolutional layer. The DownSampling is reducing the features of an array or an image. Suppose you have an input layer of (32 X 32), and you have applied 2:1 downsampling, you will have (16 x 16) layer. We Can do similarly with the images.

Step 1- Import Libraries

# example of using the upsampling layer import numpy as np from keras.models import Sequential from keras.layers import UpSampling2D

Step 2 - Define the input array and reshape it.

We will define an input array and reshape it, to feed it to the model.

# define input data X = np.array([10, 6, 3, 20]) # show input data for context print(X) # reshape input data into one sample a sample with a channel X = X.reshape((1, 2, 2, 1)) # define model model = Sequential() model.add(UpSampling2D(input_shape=(2, 2, 1))) # summarize the model model.summary() # make a prediction with the model y_pred = model.predict(X) # reshape output to remove channel to make printing easier y_pred = y_pred.reshape((4, 4)) # summarize output print(y_pred)
[10  6  3 20]
Model: "sequential_1"
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
up_sampling2d_1 (UpSampling2 (None, 4, 4, 1)           0         
=================================================================
Total params: 0
Trainable params: 0
Non-trainable params: 0
_________________________________________________________________
[[10. 10.  6.  6.]
 [10. 10.  6.  6.]
 [ 3.  3. 20. 20.]
 [ 3.  3. 20. 20.]]

Step 3 - Define Sequential model

Define the model as Sequential and add UpSampling to it.

# define model model = Sequential() model.add(UpSampling2D(input_shape=(2, 2, 1))) # summarize the model model.summary()

Step 4 - Predict the model

y_pred = model.predict(X) # reshape output to remove channel to make printing easier y_pred = y_pred.reshape((4, 4)) # summarize output print(y_pred)

Relevant Projects

Learn to prepare data for your next machine learning project
Text data requires special preparation before you can start using it for any machine learning project.In this ML project, you will learn about applying Machine Learning models to create classifiers and learn how to make sense of textual data.

Topic modelling using Kmeans clustering to group customer reviews
In this Kmeans clustering machine learning project, you will perform topic modelling in order to group customer reviews based on recurring patterns.

Forecast Inventory demand using historical sales data in R
In this machine learning project, you will develop a machine learning model to accurately forecast inventory demand based on historical sales data.

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.

Data Science Project-TalkingData AdTracking Fraud Detection
Machine Learning Project in R-Detect fraudulent click traffic for mobile app ads using R data science programming language.

Natural language processing Chatbot application using NLTK for text classification
In this NLP AI application, we build the core conversational engine for a chatbot. We use the popular NLTK text classification library to achieve this.

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.

Data Science Project - Instacart Market Basket Analysis
Data Science Project - Build a recommendation engine which will predict the products to be purchased by an Instacart consumer again.

Predict Churn for a Telecom company using Logistic Regression
Machine Learning Project in R- Predict the customer churn of telecom sector and find out the key drivers that lead to churn. Learn how the logistic regression model using R can be used to identify the customer churn in telecom dataset.

Credit Card Fraud Detection as a Classification Problem
In this data science project, we will predict the credit card fraud in the transactional dataset using some of the predictive models.