python - Keras 1.2.2 model inside other model
问题描述
I have a working piece of Keras 2.3 code which builds : an encoder, a decoder and merge them into a single Model (autoencoder) using Functional API and this method :
def merge_encoder_decoder(encoderModel, decoderModel):
input_img = encoderModel.input
output = decoderModel(encoderModel.output)
return Model(input_img, output)
Doing this, when I train the merged model, the weights are also updated in the encoder and decoder models. I need this behaviour as I use the encoder alone in a later process.
Now I want to try to distribute the train process of this model over a Hadoop cluster. For this, I've chosen the Analytics Zoo (0.6.0) framework, enabling distributed training using Spark and providing some high level APIs to build models.
My problem is : Analytics Zoo supports up to Keras 1.2.2 and I can't find a way to reproduce the behaving of my merge_encoder_decoder function in this version. More specifically, in Keras 1.2.2, Functional models don't seem to have ".input" nor ".output" attributes (that are supposed to return corresponding Tensors), and I havn't found any documentation about these attributes in the Keras 2.3's doc either.
So is there a way to do what I want in Keras 1.2.2 ?
Thanks
解决方案
Try using your own explicit Input layer:
def merge_encoder_decoder(encoderModel, decoderModel):
input_img = layers.Input(image_shape)
z = encoderModel(input_img)
output = decoderModel(z)
return models.Model(input_img, output)
推荐阅读
- python - os.path.join 抛出错误'参数类型必须是 str 或字节不是 TextIOWrapper'
- swift - 从 Fabric 迁移到 Firebase 时未提供 Google App ID 或 Google 服务文件
- google-bigquery - BigQuery:如何在分区表上运行分析函数查询
- python - 在pandas中的pivot_table之后将索引重置为平面
- javascript - setTimeout() 函数在 10 秒后显示弹出窗口
- javascript - 网站上的触发函数/具体代码
- azure-functions - How to create sessions and cookies in Azure Functions?
- wpf - 如何将委托类型参数传递给 WPF 命令
- javascript - 我可以使用汇总将依赖项捆绑在其单独的文件中吗?
- python - 如何在python中替换包含引号的字符串?