Conv2D' object has no attribute 'is_placeholder'

1,146 views
Skip to first unread message

Loser

unread,
Apr 1, 2017, 12:34:15 AM4/1/17
to Keras-users
I am currently trying to stack multiple layers together, but I am for some reason getting this error message which i am sure i understand why?


Here is an example code: 

  1. import keras
  2. from keras.layers.merge import Concatenate
  3. from keras.models import Model
  4. from keras.layers import Input, Dense
  5. from keras.layers import Dropout
  6. from keras.layers.core import Dense, Activation, Lambda, Reshape,Flatten
  7. from keras.layers import Conv2D, MaxPooling2D, Reshape, ZeroPadding2D
  8. input_img = Input(shape=(3, 6, 3))
  9. conv2d_1_1 = Conv2D(filters = 32, kernel_size = (3,3) , padding = "same" , activation = 'relu' , name = "conv2d_1_1" )(input_img)
  10. conv2d_2_1 = Conv2D(filters = 64, kernel_size = (3,3) , padding = "same" , activation = 'relu' )(conv2d_1_1)
  11. conv2d_3_1 = Conv2D(filters = 64, kernel_size = (3,3) , padding = "same" , activation = 'relu' )(conv2d_2_1)
  12. conv2d_4_1 = Conv2D(filters = 32, kernel_size = (1,1) , padding = "same" , activation = 'relu' )(conv2d_3_1)
  13. conv2d_4_1_flatten = Flatten()(conv2d_4_1)
  14. conv2d_1_2 = Conv2D(filters = 32, kernel_size = (3,3) , padding = "same" , activation = 'relu' , name = "conv2d_1_2")(input_img)
  15. conv2d_2_2 = Conv2D(filters = 64, kernel_size = (3,3) , padding = "same" , activation = 'relu' )(conv2d_1_2)
  16. conv2d_3_2 = Conv2D(filters = 64, kernel_size = (3,3) , padding = "same" , activation = 'relu' )(conv2d_2_2)
  17. conv2d_4_2 = Conv2D(filters = 32, kernel_size = (1,1) , padding = "same" , activation = 'relu' )(conv2d_3_2)
  18. conv2d_4_2_flatten = Flatten()(conv2d_4_2)
  19.  
  20. merge = keras.layers.concatenate([conv2d_4_1_flatten, conv2d_4_2_flatten])
  21. dense1 = Dense(100, activation = 'relu')(merge)
  22. dense2 = Dense(50,activation = 'relu')(dense1)
  23. dense3 = Dense(1 ,activation = 'softmax')(dense2)
  24.  
  25. model = Model(inputs = [conv2d_1_1 , conv2d_1_2] , outputs = dense3)
  26. model.compile(loss="crossentropy", optimizer="adam")
  27. print model.summary()

And error message being: 

  1. /usr/local/lib/python2.7/dist-packages/keras/engine/topology.py:1509: UserWarning: Model inputs must come from a Keras Input layer, they cannot be the output of a previous non-Input layer. Here, a tensor specified as input to "model_1" was not an Input tensor, it was generated by layer conv2d_1_1.
  2. Note that input tensors are instantiated via `tensor = Input(shape)`.
  3. The tensor that caused the issue was: conv2d_1_1/Relu:0
  4.  str(x.name))
  5. /usr/local/lib/python2.7/dist-packages/keras/engine/topology.py:1509: UserWarning: Model inputs must come from a Keras Input layer, they cannot be the output of a previous non-Input layer. Here, a tensor specified as input to "model_1" was not an Input tensor, it was generated by layer conv2d_1_2.
  6. Note that input tensors are instantiated via `tensor = Input(shape)`.
  7. The tensor that caused the issue was: conv2d_1_2/Relu:0
  8.  str(x.name))
  9. Traceback (most recent call last):
  10.  File "test_model.py", line 32, in <module>
  11.    model = Model(inputs = [conv2d_1_1 , conv2d_1_2] , outputs = dense3)
  12.  File "/usr/local/lib/python2.7/dist-packages/keras/legacy/interfaces.py", line 87, in wrapper
  13.    return func(*args, **kwargs)
  14.  File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 1562, in __init__
  15.    if layer.is_placeholder:
  16. AttributeError: 'Conv2D' object has no attribute 'is_placeholder'

I am not sure how i should interpret this error message?

Daπid

unread,
Apr 1, 2017, 3:18:40 AM4/1/17
to Loser, Keras-users
Your inputs should be the Input layers, not the convolutions. 

--
You received this message because you are subscribed to the Google Groups "Keras-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to keras-users+unsubscribe@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/keras-users/bb46ebd7-095f-4ca1-8fb4-59fbede53404%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages