添加以前在keras中的图层? - Conv2D'对象没有属性'is_placeholder'

时间:2017-04-01 02:12:43

标签: python-2.7 keras keras-layer

我似乎在keras中添加了一些问题。

示例:

import keras
from keras.layers.merge import Concatenate
from keras.models import Model
from keras.layers import Input, Dense
from keras.layers import Dropout
from keras.layers.core import Dense, Activation, Lambda, Reshape,Flatten
from keras.layers import Conv2D, MaxPooling2D, Reshape, ZeroPadding2D

input_img = Input(shape=(3, 6, 3))

conv2d_1_1 = Conv2D(filters = 32, kernel_size = (3,3) , padding = "same" , activation = 'relu' , name = "conv2d_1_1" )(input_img)
conv2d_2_1 = Conv2D(filters = 64, kernel_size = (3,3) , padding = "same" , activation = 'relu' )(conv2d_1_1)
conv2d_3_1 = Conv2D(filters = 64, kernel_size = (3,3) , padding = "same" , activation = 'relu' )(conv2d_2_1)
conv2d_4_1 = Conv2D(filters = 32, kernel_size = (1,1) , padding = "same" , activation = 'relu' )(conv2d_3_1)
conv2d_4_1_flatten = Flatten()(conv2d_4_1)

conv2d_1_2 = Conv2D(filters = 32, kernel_size = (3,3) , padding = "same" , activation = 'relu' , name = "conv2d_1_2")(input_img)
conv2d_2_2 = Conv2D(filters = 64, kernel_size = (3,3) , padding = "same" , activation = 'relu' )(conv2d_1_2)
conv2d_3_2 = Conv2D(filters = 64, kernel_size = (3,3) , padding = "same" , activation = 'relu' )(conv2d_2_2)
conv2d_4_2 = Conv2D(filters = 32, kernel_size = (1,1) , padding = "same" , activation = 'relu' )(conv2d_3_2)
conv2d_4_2_flatten = Flatten()(conv2d_4_2)


merge = keras.layers.concatenate([conv2d_4_1_flatten, conv2d_4_2_flatten])

dense1 = Dense(100, activation = 'relu')(merge)
dense2 = Dense(50,activation = 'relu')(dense1)
dense3 = Dense(1 ,activation = 'softmax')(dense2)


model = Model(inputs = [conv2d_1_1 , conv2d_1_2] , outputs = dense3)
model.compile(loss="crossentropy", optimizer="adam")

print model.summary()

为什么我无法像这样添加我的图层? 输入是一个图像,我手动分成(3,6,3)..

的形状

1 个答案:

答案 0 :(得分:1)

您的输入不正确,您自己说,输入是您的图像。更改创建模型的方式:

model = Model(inputs = input_img , outputs = dense3)

这应该有效。