【问题】Keras AttributeError: 'Tensor' object has no attribute '_keras_history'
2017-10-13 09:55
2231 查看
问题
在Keras函数式模型中加入后端函数操作时出现的错误。from keras import backend as K ... input1 = Input(shape(2,)) input2 = Input(shape(3,)) output = K.concatenate([input1,input2], axis=-1) model = Model(inputs=[input1,input2],outputs=output) ...
此时运行则会爆出错误
AttributeError: 'Tensor' object has no attribute '_keras_history'
原因可能是backend执行的操作返回值没有错误中提到的_keras_history。
解决方法
1、将backend的操作用Keras封装好的层(layer)来实现,比如上面的concatenate(),可用keras.layer.Concatenate层,或者keras.layer.concatenate函数(本质是Concatenate层的接口)。2、使用Lambda层来对操作进行封装。还是刚才的操作,代码为:
from keras.layers import Lambda ... my_concat = Lambda(lambda x: K.concatenate([x[0],x[1]],axis=-1)) output = my_concat([input1,input2]) ...
相关文章推荐
- AttributeError: 'Tensor' object has no attribute '_keras_history'
- keras example--the solution to AttributeError: 'Tensor' object has no attribute '_keras_history'
- Tensorflow protobuf版本报错问题解决(AttributeError: 'module' object has no attribute 'Default')
- Python3下AttributeError: 'dict' object has no attribute 'iteritems'的问题分析
- caffe输入层问题AttributeError: 'RoIDataLayer' object has no attribute 'param_str_'
- AttributeError 'module' object has no attribute 'handlers'--Python子模块导入问题
- TensorBoard tf.summary.merge_all() AttributeError: 'NoneType' object has no attribute 'bucket 错误
- AttributeError: 'dict' object has no attribute 'items' 问题
- Python3下AttributeError: 'dict' object has no attribute 'iteritems'的问题分析
- 上传问题之AttributeError: '_socketobject' object has no attribute 'set_tlsext_host_name'
- 解决python中问题AttributeError: 'collections.defaultdict' object has no attribute 'iteritems'
- python错误:AttributeError: 'module' object has no attribute 'setdefaultencoding'问题的解决方法
- ansible安装遇到"AttributeError: 'module' object has no attribute 'PROTOCOL_SSLv3'"的问题
- python问题请教:大佬们 AttributeError: 'int' object has no attribute 'save_bullet'
- AttributeError: 'Tensor' object has no attribute '_keras_history'
- python图像处理问题AttributeError: 'NoneType' object has no attribute 'shape'
- windows tensorflow AttributeError: 'NoneType' object has no attribute 'bucketize'
- 关于import tensorflow as tf的错误:AttributeError: type object 'NewBase' has no attribute 'is_abstract'
- tensorflow AttributeError: 'module' object has no attribute 'cpu_count'
- tensorflow AttributeError: 'module' object has no attribute 'cpu_count'