为什么Keras中的连接层会使训练非常慢?

时间:2019-01-08 14:18:54

标签: python tensorflow machine-learning keras conv-neural-network

这实际上来自我之前的问题How to apply convolution on the last three dimensions of a 5D tensor using the Conv2D in Keras?

我想对N中的每个i进行二维卷积,其维度为batch_size * N * n * n * channel_size的层。预期输出为batch_size * N * m * m * channel_size2。每个i的权重应该不同。在回答上一个问题之后,我做了以下事情:

set=[]
for i in range(N):
    conv = Conv2D(2,(4,4), strides = (4,4), activation = 'relu') \
    (Lambda(lambda x : x[:,i,:,:,:])(input_layer)) # split the tensor and apply the convolution
    resh = Reshape((1,4,4,2))(conv) #expand the dimension for concatenation
set.append(resh)


conv_layer = Concatenate(axis = 1)(set)

该代码似乎是正确的。但是它具有以下缺点:

  1. 该模型的摘要报告变得相当复杂。它将列出每个i的图层。
  2. 即使权数不是很大,网络的训练也会变得非常慢(对于N = 320)。我不确定是由于循环中的代码还是由于连接层。

任何建议将不胜感激。

0 个答案:

没有答案