首页 > 其他 > 详细

AttributeError: 'Tensor' object has no attribute '_keras_history'

时间:2019-11-14 17:20:41      阅读:719      评论:0      收藏:0      [点我收藏+]

原因是因为keras在建立网格是, 将数据流定义为Layer和Tensor会产生不兼容的现象, 因此会有这种错误.

只需要将我们tensor要进行的运算用keras提供的Lambda封装一下就可以将Tensor类型转化为为Layer类型.

 

出现错误提示的代码:

def TotalModel(input_shape, noise_model, avo_model, verbose = 1):
    
    noise_input = Input(input_shape)
    noise_output = noise_model(noise_input)
    avo_output = avo_model(noise_input)
    total_output =avo_output + noise_output

    total = Model(inputs = noise_input, outputs = total_output)
    
    if verbose == 1:
        print()
        total.summary()
    
    return total

 

修改为:

def TotalModel(input_shape, noise_model, avo_model, verbose = 1):
    
    noise_input = Input(input_shape)
    noise_output = noise_model(noise_input)
    avo_output = avo_model(noise_input)
    total_output = Lambda(lambda x: x[0] + x[1])([avo_output, noise_output])

    total = Model(inputs = noise_input, outputs = total_output)
    
    if verbose == 1:
        print()
        total.summary()
    
    return total

 

参考链接:

https://blog.csdn.net/scythe666/article/details/79962836

https://codeday.me/bug/20190131/581332.html

 

 

AttributeError: 'Tensor' object has no attribute '_keras_history'

原文:https://www.cnblogs.com/daangzi96/p/11858426.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!