EDUCBA

EDUCBA

MENUMENU
  • Blog
  • Free Courses
  • All Courses
  • All in One Bundle
  • Login
Home Data Science Data Science Tutorials Keras Tutorial UpSampling2d

UpSampling2d

UpSampling2d

Introduction to UpSampling2d

Upsampling2d creates an upsampling layer, also known as image interpolation. To repeat the column and rows by size zero and one, the upsampling2d function is used. The layer of inputs defined in 2d is upsampling2d. The layer of upsampling2d is effective and simple, but it does not perform learning and does not fill in useful details about the operation of upsampling.

Key Takeaways

  • The conv2d transpose layer is more complex as compared to the upsampling2d layer. Both layers is performing the operation of upsampling and also interpret the upsampling data.
  • This layer will combine the conv2d and upsampling layers into a single layer. We need to import libraries of UpSampling2d before using it.

What is UpSampling2d?

Each layer of upsampling2d is followed by a conv2d layer that will learn to interpret the input and train to translate the useful details. GAN is a neural network architecture that was used to train the model. The architecture will be made up of the discriminator and generator models, which will be implemented using a convolutional deep neural network. The discriminator is responsible for image classification. The generator is also responsible for generating new examples of the problem domain.

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

The generator will work by taking the random point by using latent space as input and output for completing the image. The convolutional neural network for the classification of the image is used to pool the layers for the input image down sampling. The convolutional layer is performing sown sampling by applying the filter as per the input image or feature maps. The activation which was resulting is a map of the output feature which contains the smaller border effects.

How to Use UpSampling2d?

To use upsampling2d we need to follow below steps as follows:

We need to import the different modules while using upsampling2d by using the import keyword.

1. In the below example we can see that we are importing the asarray, sequential, upsampling2d, and keras models by using the import keyword as follows.

Code:

from keras.layers import UpSampling2D
from numpy import asarray
import tensorflow as tf
from keras.models import Sequential

Output:

UpSampling2d keras models

2. Now we are defining the input data for using upsampling2d also we are printing the context of input data as follows.

Code:

ip_data = asarray ([[1, 2], [3, 4]])
print(ip_data)

Output:

UpSampling2d Input data

3. Now we are reshaping the data in a single sample. We are taking the input data for sampling as follows.

Code:

ip_data = ip_data.reshape((1, 2, 2, 1))

Output:

reshaping the data in a single sample

4. Now we are defining the model of it by using the model’s name as sequential as follows.

Code:

mod = Sequential()
mod.add(UpSampling2D (input_shape = (2, 2, 1)))
mod.summary()

Output:

UpSampling2d - Model name

5. Now in this step we are making the prediction of input data by using upsampling2d as follows.

Code:

pred = mod.predict(ip_data)

Output:

prediction of input data

6. Now in this step we are reshaping the output for removing the channel, also we are summarizing the output as follows.

Code:

pred = pred.reshape((4, 4))
print (pred)

Output:

removing the channel

tf.keras.UpSampling2D and Conv2DTranspose Layers

The tensor space model is pretrained by using initialization also we are configuring the same by using different ways. Below is the syntax of keras upsampling2d as follows:

Syntax:

tf.layers.upsampling2d(arguments)

We have defined multiple arguments with the function of upsampling2d when using it. Below example shows how we can define upsampling2d as follows:

Code:

from keras.layers import UpSampling2D
from numpy import asarray
import tensorflow as tf
import numpy as np
ip_sh = (2, 2, 1, 3)
ip = np.arange (np.prod (ip_sh)).reshape(ip_sh)
print (ip)
op = tf.keras.layers.UpSampling2D (size=(11, 22))(ip)
print (op)

Output:

UpSampling2d - Multiple arguments

UpSampling2d - Reshape

UpSampling2d 9

Con2DTranspose Layer

This is also known as the transpose convolution layer. The need for this layer generally arises from the need to shape and output of convolution for maintaining the pattern of connectivity that was compatible with the convolution. We must provide keyword arguments as input shapes by using the model’s first layer.

The conv2d transpose layer is shown in the example below:

Code:

from keras.layers import Conv2DTranspose
from numpy import asarray
import tensorflow as tf
import numpy as np
ip_sh = (2, 2, 1, 3)
ip = np.arange (np.prod(ip_sh)).reshape(ip_sh)
print(ip)
op = tf.keras.layers.Conv2DTranspose
(
    			filters,
   			 kernel_size,
   			 strides = (2, 2),
    			padding = "valid",
    			output_padding = None,
    			data_format = None,
   			 dilation_rate = (4, 4),
   			 activation = None,
  			  use_bias = True,
  bias_regularizer = None,
   			 bias_constraint = None,
)
print (op)

Output:

Con2DTranspose Layer

Transpose Layer

Models first layer

Upsampling2d Arguments

Below are the arguments for upsampling as follows. It will accept the object of the field as follows.

  • Size – The type of size argument is float. Row and column are an upsampling factor. It contains the numbers array.
  • Shape – The type of shape argument is int. It contains the instruction as an output shape. This argument is used to create the input layer which was used for inserting the same before the layer.
  • Name – The type of name argument is a string. This is defined as the name of the layer.
  • Color – The type of color argument is a color format. This argument is defined as layer color.
  • Close button – The type of close button argument is dict. Close button will appear as a control dict.
  • Init status – The type of init status argument is a string. The layer initial status of upsampling2d is open or closed.
  • Animetime – The type of anime time argument is int. It will define the speed of open and closed animation.
  • Dataformat – These arguments will determine the ordering of input data format in an input dimension.
  • Interpolation – It will define the mechanism of interpolation. The value of this argument is nearest.
  • Batch size – This argument is defined in the absence of batch input shape.
  • Dtype – The suppose layer is used as an input layer then this field is used as the data type.
  • Weights – This is defined as tensor which was defining the value of initial weights.
  • Batch input shape – It will define array numbers. This arguments is used in absence of batch size.

Examples of UpSampling2d

Given below are the examples mentioned:

Example #1

In the below example, we are using the function of upsampling2d as follows.

Code:

from keras.layers import UpSampling2D
from numpy import asarray
import tensorflow as tf
from keras.models import Sequential
ip = asarray([[11, 21],
			 [31, 41]])
print(ip)
ip = ip.reshape((1, 2, 2, 1))
conv = Sequential()
conv.add(UpSampling2D (input_shape = (2, 2, 1)))
conv.summary()
pred_2d = conv.predict(ip)
pred_2d = pred_2d.reshape((4, 4))
print(pred_2d)

Output:

UpSampling2d Functions

Example #2

In below example we are defining the keras upsampling as follows.

Code:

from keras.layers import UpSampling2D
from numpy import asarray
import tensorflow as tf
import numpy as np
ip_spape = (2, 2, 1, 1)
ip = np.arange (np.prod (ip_spape)).reshape(ip_spape)
print (ip)
op = tf.keras.layers.UpSampling2D (size=(1, 2))(ip)
print (op)

Output:

Keras UpSampling2d

Conclusion

Generator will work by taking the random point by using latent space as input and output for completing the image. It is creating a layer of upsampling, which is also known as image interpolation. The upsampling2d function is used to repeat the column and rows by size zero and one.

Recommended Articles

This is a guide to UpSampling2d. Here we discussed the introduction, how to use UpSampling2d? arguments and examples. You may also have a look at the following articles to learn more –

  1. Keras Tuner
  2. What is Keras GPU?
  3. Keras Embedding
  4. Keras predict
All in One Excel VBA Bundle
500+ Hours of HD Videos
15 Learning Paths
120+ Courses
Verifiable Certificate of Completion
Lifetime Access
Financial Analyst Masters Training Program
1000+ Hours of HD Videos
43 Learning Paths
250+ Courses
Verifiable Certificate of Completion
Lifetime Access
All in One Data Science Bundle
1500+ Hour of HD Videos
80 Learning Paths
360+ Courses
Verifiable Certificate of Completion
Lifetime Access
All in One Software Development Bundle
3000+ Hours of HD Videos
149 Learning Paths
600+ Courses
Verifiable Certificate of Completion
Lifetime Access
Primary Sidebar
All in One Data Science Bundle1500+ Hour of HD Videos | 80 Learning Paths | 360+ Courses | Verifiable Certificate of Completion | Lifetime Access
Financial Analyst Masters Training Program1000+ Hours of HD Videos | 43 Learning Paths | 250+ Courses | Verifiable Certificate of Completion | Lifetime Access
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2023 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more