如何为keras DL培训输入多个输出?

2024-04-25 22:58:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我想制作一个使用多个输出的网络。 例如,我想输入一个具有以下形状的列表: [ 8, 128, 128, 3] 这里,8是一组输入中的图像数,128 x 128 x 3是彩色图像的形状。 我希望我的输出是: [ 8, 128, 128] 这里,8是一组输出中的图像数,128 x 128是灰色图像的形状

因此,我的代码如下所示:

f_list = []
for i in range(v):
    img_in = M.Input((h, w, 3))  # Input :
    feature = spm.encoder(img_in)
    f_list.append(feature)
fuse_ave,fuse_max,fuse_min = spm.fusion(f_list)
decode_list = []
for i in range(v):
    ffuse = spm.decoder(f_list[i],fuse_ave,fuse_max)
    decode_list.append(ffuse)
dl_con = L.concatenate(decode_list,0)
print(dl_con.shape)
epsnet = M.Model(inputs = img_in,outputs = dl_con)
epsnet.compile(optimizer=O.Adam(lr=0.0001,decay = 0.000001), loss='mean_squared_error', metrics=['accuracy'])
epsnet.fit(iml,np.array(gml),batch_size = 5, epochs=50,verbose=1,shuffle=True, validation_split=0.1)

这里,解码功能如下:

def decoder(input,fuse_a,fuse_M):    #input : encoded
    infu = L.Concatenate(-1)([input,fuse_a,fuse_M])
    f=128
    x = L.Conv2DTranspose(filters = f,kernel_size=(5,5),strides=2,padding = 'same')(infu)   dding = 'same')(x__)

          ...

    x__ = L.BatchNormalization()(x__)
    x__ = L.Activation('relu')(x__)
    def sq(x):
        x_sq = B.squeeze(x,-1)
        return x_sq
    xq = L.Lambda(sq)(x__)
    return xq

我在这里得到错误消息:

 ValueError: Output tensors to a Model must be the output of a TensorFlow `Layer` (thus holding past layer metadata). Found: Tensor("concatenate_7/concat:0", shape=(?, ?, ?), dtype=float32)

我尝试了几种方法,但仍然收到相同的错误消息。请给我一个突破,非常感谢


Tags: in图像imgforinputsqrangecon