首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >'NoneType‘对象没有属性'_inbound_nodes’错误

'NoneType‘对象没有属性'_inbound_nodes’错误
EN

Stack Overflow用户
提问于 2020-05-11 08:43:24
回答 1查看 269关注 0票数 1

我必须取EfficientNet最后一层的输出,然后计算出H= wT*x+b,我的w是49。在此之后,我必须在H上应用softmax,然后进行元素乘法Xμ= Hi*Xi。这是我的密码:

代码语言:javascript
复制
common_input = layers.Input(shape=(224, 224, 3))    
x=model0(common_input) #model0 terminate with last conv layer of EfficientNet (7,7,1280)
x = layers.BatchNormalization()(x)

W = tf.Variable(tf.random_normal([49,49], seed=0), name='weight')
b = tf.Variable(tf.random_normal([49], seed=0), name='bias')

x = tf.reshape(x, [-1, 7*7,1280])
H = tf.matmul(W, x,transpose_a=True)
H = tf.nn.softmax(H)
#print(H.shape) (?,49,1280)
#print(x.shape) (?,49,1280)

x=tf.multiply(H, x)

p=layers.Dense(768, activation="relu")(x)
p=layers.Dense(8, activation="softmax", name="fc_out")(p)

model = Model(inputs=common_input, outputs=p)

但是我得到了一个错误:'NoneType‘对象没有属性'_inbound_nodes’

代码语言:javascript
复制
<ipython-input-12-6ce3217f045c> in build_model()
     35     p=layers.Dense(8, activation="softmax", name="fc_out")(p)
     36 
---> 37     model = Model(inputs=common_input, outputs=p)
     38 
     39     return model

AttributeError: 'NoneType' object has no attribute '_inbound_nodes'
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-05-11 11:26:23

在下面的代码中,我已经用Lambda层替换了操作。请原谅我那拙劣的名字。试试看这段代码。

代码语言:javascript
复制
W = tf.Variable(tf.random_normal([49,49], seed=0), name='weight')
b = tf.Variable(tf.random_normal([49], seed=0), name='bias')

def all_operations(args):
    x = args[0]
    H = args[1]
    x = tf.reshape(x, [-1, 7*7,1280])
    H = tf.matmul(W, x, transpose_a=True)
    H = tf.nn.softmax(H)
    x = tf.multiply(H, x)
    x = tf.reshape(x, [-1, 49*1280])
    return x

common_input = layers.Input(shape=(224, 224, 3))    
x=model0(common_input) #model0 terminate with last conv layer of EfficientNet (7,7,1280)
x = layers.BatchNormalization()(x)

x = Lambda(all_operations)([x, H])

p=layers.Dense(768, activation="relu")(x)
p=layers.Dense(8, activation="softmax", name="fc_out")(p)

model = Model(inputs=common_input, outputs=p)
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61725611

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档