conv2d的输入_层conv2d_3的输入不是符号张量

hi I am building a image classifier for one-class classification in which i've used autoencoder while running this model I am getting this error (ValueError: Layer conv2d_3 was called with an input that isn't a symbolic tensor. Received type: . Full input: [(128, 128, 3)]. All inputs to the layer should be tensors.)

num_of_samples = img_data.shape[0]

labels = np.ones((num_of_samples,),dtype='int64')

labels[0:376]=0

names = ['cat']

Y = np_utils.to_categorical(labels, num_class)

input_shape=img_data[0].shape

x,y = shuffle(img_data,Y, random_state=2)

X_train, X_test, y_train, y_test = train_test_split(x, y, test_size=0.2, random_state=2)

x = Conv2D(16, (3, 3), activation='relu', padding='same')(input_shape)

x = Conv2D(8, (3, 3), activation='relu', padding='same')(x)

x = MaxPooling2D((2, 2), padding='same')(x)

x = Conv2D(8, (3, 3), activation='relu', padding='same')(x)

encoded = MaxPooling2D((2, 2), padding='same')(x)

# at this point the representation is (4, 4, 8) i.e. 128-dimensional

x = Conv2D(8, (3, 3), activation='relu', padding='same')(encoded)

x = UpSampling2D((2, 2))(x)

x = Conv2D(8, (3, 3), activation='relu', padding='same')(x)

x = UpSampling2D((2, 2))(x)

x = Conv2D(16, (3, 3), activation='relu')(x)

x = UpSampling2D((2, 2))(x)

decoded = Conv2D(1, (3, 3), activation='sigmoid', padding='same')(x)

autoencoder = Model(input_shape, decoded)

autoencoder.compile(optimizer='adadelta', loss='binary_crossentropy')

autoencoder.fit(X_train, X_train,

epochs=50,

batch_size=32,

shuffle=True,

validation_data=(X_test, X_test),

callbacks=[TensorBoard(log_dir='/tmp/autoencoder')])

解决方案

Here:

x = Conv2D(16, (3, 3), activation='relu', padding='same')(input_shape)

A shape is not a tensor.

Do this:

from keras.layers import *

inputTensor = Input(input_shape)

x = Conv2D(16, (3, 3), activation='relu', padding='same')(inputTensor)

Hint about autoencoders

You should separate the encoder and decoder as individual models. Later you will probably want to work with only one of them.

Encoder:

inputTensor = Input(input_shape)

x = ....

encodedData = MaxPooling2D((2, 2), padding='same')(x)

encoderModel = Model(inputTensor,encodedData)

Decoder:

encodedInput = Input((4,4,8))

x = ....

decodedData = Conv2D(1, (3, 3), activation='sigmoid', padding='same')(x)

decoderModel = Model(encodedInput,decodedData)

Autoencoder:

autoencoderInput = Input(input_shape)

encoded = encoderModel(autoencoderInput)

decoded = decoderModel(encoded)

autoencoderModel = Model(autoencoderInput,decoded)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值