zoukankan      html  css  js  c++  java
  • Keras AttributeError 'NoneType' object has no attribute '_inbound_nodes'

    问题说明:

    首先呢,报这个错误的代码是这行代码:

    model = Model(inputs=input, outputs=output)
    

    报错:

     AttributeError 'NoneType' object has no attribute '_inbound_nodes'
    

    解决问题:

    本人代码整体采用Keras Function API风格,其中使用代码中使用了concatenate以及reshape这两个方法,具体使用:

    from keras import backend as K
    from keras.layers import Dense, Input
    
    inpt = Input(shape=(224, 224, 3))
    x = Conv2d(63, (3,3), padding='same', activation='relu')
    ...
    x = K.concatenate([branch1, branch2, branch3], axis=3)
    x = K.reshpe(x, (1000,))
    # 上面两行代码并不是连续出现,这里写出来,主要描述使用了“连接”“reshape”两种操作;
    

    或许,在你的代码中也存在这两行代码,又或者使用了类似的一些方法,问题就出在这里:

    x = K.concatenate([branch1, branch2, branch3], axis=3)
    x = K.reshpe(x, (1000,))
    

    将之修改为:

    from keras.layers import Concatenate, Resahpe
    
    x = Concatenate(axis=3)([branch1, branch2, branch3])
    x = Resahpe((1000,))(x)
    

    可以想到,直接使用concatenate或者reshape不是作为一层,而Concatenate或者Reshape是一个layer;

    那么,类似的错误都可以按照这个思路来检查代码吧。

  • 相关阅读:
    OpenCV (一)图片读取、修改、保存
    用matplotlib进行数据分析(可视化)
    笔记
    vrpano
    四、threejs——模型交互
    三、threejs不显示英文就是乱码情况,中文解决方案
    二、GLTF模型支持
    一、threejs————灯光阴影
    node的httpserver简单创建
    em和rem区别
  • 原文地址:https://www.cnblogs.com/chenzhen0530/p/10893803.html
Copyright © 2011-2022 走看看