Convolution Neural Network Using Tensorflow
Convolution Neural Network is a widely used Deep Learning algorithm. The main purpose of using CNN is to scale down the input shape. In the example below we take 4 dimension image pixels with a total number of 50 images data of 64 pixels. Since we know that an image is made of three colors i.e. RGB, thus the 4 value 3 denotes a color image.
On passing the input image pixel to Conv2D it scales down the input size.
Example:
Python3
import tensorflow as tf import tensorflow.keras as keras image_pixel = ( 50 , 64 , 64 , 3 ) cnn_feature = tf.random.normal(image_pixel) cnn_label = keras.layers.Conv2D( 2 , 3 , activation = 'relu' , input_shape = image_pixel[ 1 :])( cnn_feature) print (cnn_label.shape) |
Output:
(50, 62, 62, 2)
By providing padding argument as same the input size shall remain the same.
Python3
image_pixel = ( 50 , 64 , 64 , 3 ) cnn_feature = tf.random.normal(image_pixel) cnn_label = keras.layers.Conv2D( 2 , 3 , activation = 'relu' , padding = "same" , input_shape = image_pixel[ 1 :])(cnn_feature) print (cnn_label.shape) |
Output:
(50, 64, 64, 2)
The pixel-sized is unchanged as we have provided padding to be the same.
Python Tensorflow – tf.keras.layers.Conv2D() Function
In this article, we shall look at the in-depth use of tf.keras.layers.Conv2D() in a python programming language.