Question

In: Computer Science

Calculate the input and output dimension for each convolution and pooling layer in DeepSEA (100pts)

Calculate the input and output dimension for each convolution and pooling layer in DeepSEA (100pts)

Solutions

Expert Solution

Input Output dimensions in Convultion-

Input Shape- Give a 4D array as input to the CNN. So input data has a shape of (batch_size, height, width, depth), where the first dimension represents the batch size of the image and the other three dimensions represent dimensions of the image which are height, width, and depth. For some of you who are wondering what is the depth of the image, it’s nothing but the number of color channels. For example, an RGB image would have a depth of 3, and the greyscale image would have a depth of 1.

Output Shape- The output of the CNN is also a 4D array. Where batch size would be the same as input batch size but the other 3 dimensions of the image might change depending upon the values of filter, kernel size, and padding we use.

Let’s look at the following code snippet

Input_shape argument looks like out input shape is 3D, but you have to pass a 4D array at the time of fitting the data which should be like (batch_size, 10, 10, 3). Since there is no batch size value in the input_shape argument, we could go with any batch size while fitting the data.

As you can notice the output shape is (None, 10, 10, 64). The first dimension represents the batch size, which is None at the moment. Because the network does not know the batch size in advance. Once you fit the data, None would be replaced by the batch size you give while fitting the data.

Let’s look at another code snippet.

Here we

have replaced input_shape argument with batch_input_shape. As the name suggests, this argument will ask you the batch size in advance, and you can not provide any other batch size at the time of fitting the data. For example, you have to fit the data in the batch of 16 to the network only.

Now you can see that output shape also has a batch size of 16 instead of None.

----------------------------------------------------------------------------------------------------------------------------------------------------------

Input and Output dimensions for Pooling Layer-

The result of using a pooling layer and creating down sampled or pooled feature maps is a summarized version of the features detected in the input. They are useful as small changes in the location of the feature in the input detected by the convolutional layer will result in a pooled feature map with the feature in the same location. This capability added by pooling is called the model’s invariance to local translation.

In all cases, pooling helps to make the representation become approximately invariant to small translations of the input. Invariance to translation means that if we translate the input by a small amount, the values of most of the pooled outputs do not change.

Example with pooling-

# example of average pooling
from numpy import asarray
from keras.models import Sequential
from keras.layers import Conv2D
from keras.layers import AveragePooling2D
# define input data
data = [[0, 0, 0, 1, 1, 0, 0, 0],
                [0, 0, 0, 1, 1, 0, 0, 0],
                [0, 0, 0, 1, 1, 0, 0, 0],
                [0, 0, 0, 1, 1, 0, 0, 0],
                [0, 0, 0, 1, 1, 0, 0, 0],
                [0, 0, 0, 1, 1, 0, 0, 0],
                [0, 0, 0, 1, 1, 0, 0, 0],
                [0, 0, 0, 1, 1, 0, 0, 0]]
data = asarray(data)
data = data.reshape(1, 8, 8, 1)
# create model
model = Sequential()
model.add(Conv2D(1, (3,3), activation='relu', input_shape=(8, 8, 1)))
model.add(AveragePooling2D())
# summarize model
model.summary()
# define a vertical line detector
detector = [[[[0]],[[1]],[[0]]],
            [[[0]],[[1]],[[0]]],
            [[[0]],[[1]],[[0]]]]
weights = [asarray(detector), asarray([0.0])]
# store the weights in the model
model.set_weights(weights)
# apply filter to input data
yhat = model.predict(data)
# enumerate rows
for r in range(yhat.shape[1]):
        # print each column in the row
        print([yhat[0,r,c,0] for c in range(yhat.shape[2])])

Running the example first summarizes the model.

We can see from the model summary that the input to the pooling layer will be a single feature map with the shape (6,6) and that the output of the average pooling layer will be a single feature map with each dimension halved, with the shape (3,3).


Related Solutions

1:Find the convolution output volume size of layer 2 (W2xH2xD2) and 3 (W3xH3xD3) 2: Find the...
1:Find the convolution output volume size of layer 2 (W2xH2xD2) and 3 (W3xH3xD3) 2: Find the convolution output volume size of layer 2 (W2xH2xD2) and 3 (W3xH3xD3) 3: Find the output volume size of output pooling layer (W2xH2xD2)
The input-output (consumption) matrix for a closed economy is given below. Solve the associated input- output...
The input-output (consumption) matrix for a closed economy is given below. Solve the associated input- output model. Use r if you need a variable in your answer. [0.07 0.05 0.27] [0.17 0.48 0.19] [0.76 0.47 0.54]
Answer the following questions using R (include both the input and output for each question). I)...
Answer the following questions using R (include both the input and output for each question). I) A random variable P has a Poisson distribution with a mean of 10. Solve for the probability that random variable P is greater than 8. II) What is the probability that in 30 tosses of a fair coin, the head comes up 10 or 15 times? III) What is the probability that a normal random variable is less than 40, assuming that the variable...
Answer the following questions using R (include both the input and output for each question). I)...
Answer the following questions using R (include both the input and output for each question). I) A random variable P has a Poisson distribution with a mean of 10. Solve for the probability that random variable P is greater than 8. II) What is the probability that in 30 tosses of a fair coin, the head comes up 10 or 15 times? III) What is the probability that a normal random variable is less than 40, assuming that it has...
computer ,input and output device sof computer
What is computer list some input and output devices  of compueter.
(Written in C)The input below shows a grid dimension (first line), the following 2 are the...
(Written in C)The input below shows a grid dimension (first line), the following 2 are the positions of the start cell and end cell, and the rest is the positions of cells blocked. Keep in mind that the input is an txt file to be read through stdin (you can not type input multiple times). How do I read the input using scanf . Also, it is not allow to store input into array (because we can not assume the...
Modify the following code to make the input and output look like this. Input 5 Vader...
Modify the following code to make the input and output look like this. Input 5 Vader 1300 Kirk 1250 Adama 1000 Reynolds 1615 Oneill 1470 Output Enter the number of candidates: 5 Enter candidate's name :Vader 1300 Enter votes received :Enter candidate's name :Kirk 1250 Enter votes received :Enter candidate's name :Adama 1000 Enter votes received :Enter candidate's name :Reynolds 1615 Enter votes received :Enter candidate's name :Oneill 1470 Enter votes received : Name Votes Percentage Vader 1300.00 19.59% Kirk...
Consider the dataset regarding the drop in light percent output (output) and two input variables –...
Consider the dataset regarding the drop in light percent output (output) and two input variables – bulb surface (qualitative) and length of the operation hours (quantitative). The data is available in a sheet named ‘Problem 3’. Answer the following. (a) Write down the overall model form if one wishes to build a second order model for each value of the qualitative variable (c) Build a regression model showing the 90% confidence ranges of the regression parameters. Write down the mean...
Explain linear convolution for continuous and discrete domain signals? provide an example for each case.
Explain linear convolution for continuous and discrete domain signals? provide an example for each case.
Which of the following can serve as both an input to and an output of the...
Which of the following can serve as both an input to and an output of the acquisition / payment process? Check Purchase Order Both A and B Neither A and B
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT