如何使用Keras建立模型并重用图层?

时间:2019-07-08 07:53:16

标签: tf.keras

我的数据形状为[91,109,91,27],我将一个数据分解为27个形状为[91,109,91,1]的数据,

我想使用convnet提取功能。 但是这里是循环我的网络27次。 那么我怎么能只重用网络一次?

代码注释中的问题描述

x_in = Input(shape=shape) # my data shape is [91,109,91,27]

x = Lambda(self.unstack)(x_in) # there I unstack the data to 27 datas shape is [91,109,91]

t_list = []
for i in range(len(x)): # loop 27 times
   x_expand = Lambda(self.expand)(x[i])  # change the data shape to [91,109,91,1]

   feature = self.cnn_block(x_expand)# here is my Net with 3 convs --->
# I build a convnet here, and I want to reuse the network, but here it is looping 27 times. so is there a way to reuse the cnn_block in keras?

   x_out = Lambda(self.expand)(feture)
   t_list.append(x_out)

x = Concatenate(axis=-1)(t_list)

0 个答案:

没有答案