简体   繁体   中英

Keras Minimum() causing AttributeError: 'NoneType' object has no attribute '_inbound_nodes'

What is going on, and how do I correctly use Keras' Minimum() layer?

start = Input(shape=(28,28,1), dtype='float32')
c = Conv2D(20,3,use_bias=False,data_format="channels_last",input_shape=(28, 28, 1),padding='same')(start)
c = Reshape((28,28,20,1))(c)
m = MaxPooling3D(pool_size=(1,1,20), strides=1, padding='valid', data_format="channels_last")(c)
m = Reshape((28,28,1))(m)
m = Minimum()([m,mask])
print(m.shape, mask.shape)
f = Flatten()(m)
print(f.shape)
out = Dense(10,activation='softmax')(f)
model = Model(inputs=start, outputs=out)

output:

(60000, 28, 28, 1) (60000, 28, 28, 1)
(60000, 784)

AttributeError                            Traceback (most recent call last)
<ipython-input-21-e0fab99c12c2> in <module>()
      9 print(f.shape)
     10 out = Dense(10,activation='softmax')(f)
---> 11 model = Model(inputs=start, outputs=out)

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

The keras API says that Minimum() is:

Layer that computes the minimum (element-wise) a list of inputs.

It takes as input a list of tensors, all of the same shape, and returns a single tensor (also of the same shape).

So it seems like I am using it correctly to me... but I am probably doing something very stupid.

I solved the problem. It's my mistake. I was trying to pass mask to minimum(), but mask was a numpy array and minimum() needs a Keras Input()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM