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


原因是因为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

 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM