【AAE】【Keras】实现merge出错:TypeError: ‘module‘ object is not callable
在运行AAE的git代码时,发现encoder的构建中,有一行是报错的:
latent_repr = merge([mu, log_var],mode=lambda p: p[0] + K.random_normal(K.shape(p[0])) * K.exp(p[1] / 2),output_shape=lambda p: p[0])
报错显示merge有问题:TypeError: 'module' object is not callable
原因分析:
查看了 keras关于Merging layer的文档,发现现在的keras.layer中并不存在merge这个方法。keras.layer只提供以下几个方法
- Concatenate layer
- Average layer
- Maximum layer
- Minimum layer
- Add layer
- Subtract layer
- Multiply layer
- Dot layer
解决办法:对merge进行改写。
若merge( [Layer] , mode, output_shape) 中的mode = 'concat' , 则需要使用Concatenate方法, 若mode='multi' 则换成Multiply方法
merge6 = merge([drop4, up6], mode='concat', concat_axis=3)# 换成:
from keras.layers import Concatenate
merge6 = Concatenate(axis=3)([drop4, up6])
若merge( [Layer] , mode, output_shape) 中的mode =是一个复杂的公式,则需要自己创建一个class
latent_repr = merge([mu, log_var],mode=lambda p: p[0] + K.random_normal(K.shape(p[0])) * K.exp(p[1] / 2),output_shape=lambda p: p[0])# 换成:# 1 新建一个MergeLayer.py文件如下
from keras.engine.base_layer import Layer
import keras.backend as Kclass MergeLayer(Layer):def __init__(self, **kwargs):super(MergeLayer, self).__init__(**kwargs)def compute_output_shape(self, input_shape):return (input_shape[0][0], input_shape[0][1])def call(self, x, mask=None):final_output = x[0] + K.random_normal(K.shape(x[0])) * K.exp(x[1] / 2)return final_output# 2 在原方法中引用并调用这个类的方法:
from MergeLayer import MergeLayer
latent_repr = MergeLayer()([mu, log_var])
参考博客
【AAE】【Keras】实现merge出错:TypeError: ‘module‘ object is not callable相关推荐
- 菜尼奥排错之merge6 = merge([drop4,up6], mode = ‘concat‘...)TypeError: ‘module‘ object is not callable
环境版本: Ubuntu 18.04.2 LTS Nvidia GeForce RTX2080super CUDA Version 10.0 tensorflow-gpu 1.13.1 keras 2 ...
- python import 错误 TypeError: 'module' object is not callable
python import 错误 TypeError: 'module' object is not callable 在这里,有 Person.py test.py; 在 test.py 里面 im ...
- TypeError: 'module' object is not callable 原因分析
程序代码 class Person: #constructor def __init__(self,name,sex): self.Name = name ...
- Python导入模块(包)的两种方式 TypeError: 'module' object is not callable
Python编程时明明在开始处import了相关包,但是调用函数时就报错如下: TypeError: 'module' object is not callable Python中有两种导入包(模块, ...
- TypeError: 'module' object is not callable 原因分析(python模块导入注意事项)
程序代码 class Person: #constructor def __init__(self,name,sex): self.Name = name ...
- TypeError: 'module' object is not callable (pytorch在进行MNIST数据集预览时出现的错误)
在使用pytorch在对MNIST数据集进行预览时,出现了TypeError: 'module' object is not callable的错误: 上报错信息图如下: 从图中可以看出,报错位置为第 ...
- Running pipenv gives TypeError: 'module' object is not callable
Running pipenv gives TypeError: 'module' object is not callable 记一次项目使用pipenv安装虚拟环境遇到的问题 导致上述报错的原因: ...
- Python 3.8+moviepy报错:TypeError: ‘module‘ object is not callable
☞ ░ 老猿Python博文目录:https://blog.csdn.net/LaoYuanPython ░ 一.引言 最近有博友在博文< https://blog.csdn.net/LaoYu ...
- 自动化测试PyCharm运行后提示:TypeError: ‘module‘ object is not callable
如图所示:我运行PyCharm时提示:TypeError: 'module' object is not callable 第一点根据异常提示发现 line 10, in driver = webdr ...
- python TypeError: ‘module‘ object is not callable
这个问题一般是使用import 的时候模块没有导入问题引起的,所以你需要检查下导入的模块了 例如我的这个提示如下 提示 random.random() 提示这个地方出现了问题 代码如下 感觉也没有问题 ...
最新文章
- 首长,Redis性能优化十三条军规立好了,请过目~
- python乘法口诀表-如何用python语言发出乘法口诀表
- python循环报数游戏_python经典面试题之一:猴子报数
- [!] Attempt to read non existent folder `***********`
- 计算机做游戏到大学要学什么,大学学什么专业,毕业才能从事电竞行业?
- 如何查看一个组件的 classid是多少_万一免五(万1免5)是骗人的吗?如何查看自己的交易费率是多少?万一免五最新问题汇总!...
- Ecshop 商品页配送方式添加 实现仿淘宝按地区显示运费
- 【实用工具】查看gcc/vs开启的宏
- 使用idea上传项目到gitHub
- 使用Microsoft Lookback网卡解决了断网情况下 Virtual Server 虚机和主机的网络连接
- spring-bean(xml方式管理)
- 李宏毅自然语言处理——ELMO/BERT/GPT简介
- java - 常见对象object
- 数组中第三大的数 leetcode 414
- Flightgear 编译
- 互联网专用计算机屏保,5款屏保,让你的电脑在闲置时也与众不同。
- Java多线程面试题(面试必备)
- Ubuntu16.04常用工具
- 腾讯精选50题—Day6题目43,46,53
- 2020高交会第二十二届中国国际高新技术成果交易会
热门文章
- 南京信息工程大学python期末考试_南京信息工程大学的雷丁学院怎么样?
- css动画效果轮播图片
- 寻找“安全圈锦鲤” | 4万粉丝,独宠你一人(倒计时2天)
- android 系统vr,Android系统中的PowerVR成像框架
- 钉钉发起审批流程分析
- 审批流程展示html,审批流程图怎么绘制?不懂可以看这里
- NAT地址转换顺序:inside→outside先路由再转换;outside→inside先转换再路由
- 《大学》修身、齐家、治国、平天下
- 社会心理学(第8版)
- 电脑如何设置定时任务、定时执行 —— 不用Windows任务计划程序,也能轻松设定计划任务、定时任务 —— 定时执行专家