2019-01-07 13:31:16 8 Comments

Usually the input tensor of the `Conv2D`

in Keras is a 4D tensor with the dimension `batch_size * n * n * channel_size`

. Now I have a 5D tensor with the dimension `batch_size * N * n * n * channel_size`

and I want to apply the 2D convolutional layer for the last three dimensions for each i in `N`

. For example, if the kernel size is 1, then I expect that the output will have the dimension `batch_size * N * n * n * 1`

.

Anyone knows some easy ways to implement it with Keras?

For example, for the fully-connected layer Keras can do it automatically. If the input has the shape `batch_size * N * n`

, then the Dense layer in Keras will set a FC layer for each i in `N`

. Hence we will get the output with `batch_size * N * m`

, if we set `Dense(m)`

.

### Related Questions

#### Sponsored Content

#### 3 Answered Questions

### How to fix "symbolic tensors" use "steps_per_epoch" but not "batch_size" bug in a simple conv2d+liquid state machine net

**2019-05-21 16:08:54****Zhongrui Wang****759**View**1**Score**3**Answer- Tags: tensorflow keras

#### 5 Answered Questions

### [SOLVED] Negative dimension size caused by subtracting 3 from 1 for 'conv2d_2/convolution'

**2017-08-12 00:02:55****Mohammad Nurdin****30981**View**16**Score**5**Answer- Tags: python tensorflow neural-network keras keras-layer

#### 1 Answered Questions

### Keras Dropout Convolutional Filters

**2019-07-15 13:23:54****Markus Weber****134**View**1**Score**1**Answer- Tags: python tensorflow keras conv-neural-network dropout

#### 3 Answered Questions

#### 1 Answered Questions

### [SOLVED] Delete last layer and insert three Conv2D layers in Keras

**2018-09-21 10:38:44****Alem****246**View**0**Score**1**Answer- Tags: python machine-learning keras conv-neural-network keras-layer

#### 1 Answered Questions

### [SOLVED] How to model Convolutional recurrent network ( CRNN ) in Keras

**2018-01-20 13:02:41****harish2704****4173**View**5**Score**1**Answer- Tags: keras lstm recurrent-neural-network pytorch

#### 1 Answered Questions

### [SOLVED] Why do Keras Conv1D layers' output tensors not have the input dimension?

**2017-07-13 16:56:46****profPlum****3524**View**5**Score**1**Answer- Tags: python keras conv-neural-network tensor

#### 1 Answered Questions

### [SOLVED] input dimensions to a one dimensional convolutional network in keras

**2016-07-29 10:30:23****Nick****11099**View**22**Score**1**Answer- Tags: python neural-network theano conv-neural-network keras

## 1 comments

## @today 2019-01-07 13:38:09

You can use the

`TimeDistributed`

layer wrapper to apply the same convolution layer on all the images in the 5D tensor. For example:Model summary:

## @Z. Ye 2019-01-07 13:39:17

Very quick answer! I will try that at once :)

## @Z. Ye 2019-01-07 14:16:26

It actually works but not exactly in a way that I expected. It seems that the weights are the same for every temporal parameter i in N. However, I wanted to set different weights for each i.

## @today 2019-01-07 14:26:43

@Z.Ye Of course and I mentioned that in my answer. Further, that's also the case for the

`Dense`

layer example you provided, i.e. the weights are fixed. If you want different weights and the`N`

is known, you can easily write a for loop to do that.## @Z. Ye 2019-01-07 14:33:24

Yes, you are right. The Dense layer also did what you described. Then I will try loop.

## @Z. Ye 2019-01-08 14:19:49

I'm sorry that I can not upvote your answer. I tried the for loop a bit, but it didn't not work perfectly. I posted a question here stackoverflow.com/questions/54093755/… . Could you give me a hint? Thank you very much.