将keras模型输入输入到输出层 [英] Feed keras model input to the output layer

查看:44
本文介绍了将keras模型输入输入到输出层的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我正在构建一个keras顺序模型,其中最后一个输出层是Upsampling2D层&我需要将输入图像馈送到该输出层以执行简单的操作并返回输出,有什么想法吗?

So I am building a keras sequential model in which the last output layer is an Upsampling2D layer & I need to feed the input image to that output layer to do a simple operation and return the output, any ideas?

之前提到的模型是GAN模型的生成器,在该模型中,我需要先将输入图像添加到生成器的输出中,然后再将其提供给鉴别器

The model mentioned before is the generator of a GAN model in which I need to add the input image to the output of the generator before feeding it to the discriminator

推荐答案

因此,为了以后的参考,我通过使用如下的lambda层解决了该问题:

So for the future reference, I solved it by using lambda layers as follow :

# z is the input I needed to use later on with the generator output to perform a certain function

generated_image = self.generator(z)        
generated_image_modified=tf.keras.layers.Concatenate()([generated_image,z])

# with x[...,variable_you_need_range] you can access the input we just concatenated in your train loop

lambd = tf.keras.layers.Lambda(lambda x: your_function(x[...,2:5],x[...,:2]))(generated_image_modified)

full_model = self.discriminator(lambd)
self.combined = Model(z,outputs = full_model)

这篇关于将keras模型输入输入到输出层的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆