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

Data Science Project in Python on BigMart Sales Prediction
The goal of this data science project is to build a predictive model and find out the sales of each product at a given Big Mart store.

Data Science Project on Wine Quality Prediction in R
In this R data science project, we will explore wine dataset to assess red wine quality. The objective of this data science project is to explore which chemical properties will influence the quality of red wines.

Time Series Forecasting with LSTM Neural Network Python
Deep Learning Project- Learn to apply deep learning paradigm to forecast univariate time series data.

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.

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.

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.

Walmart Sales Forecasting Data Science Project
Data Science Project in R-Predict the sales for each department using historical markdown data from the Walmart dataset containing data of 45 Walmart stores.

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.

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.

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.