hiambuildingaimageclassifierforone-classclassificationinwhichi ' veusedautoencoderwhilerunningthismodeliamgetttingthiseror eror dwithaninputthatisn ' tasymbolictensor.received type :full input : [ (128、128、128、128、128、128、128、128、128、128 )
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=最大轮询2d ((2,2 ),填充=' same ' ) (x ) ) ) ) ) )。
x=conv2d(8,(3,3 ),activation='relu ',padding='same ' () (x ) ) ) ) ) ) ) ) )
编码=最大轮询2d ((2,2 ),填充=' same ' ) (x ) ) ) ) ) ) )。
# atthispointtherepresentationis (4,4,8 ) i.e. 128-dimensional
x=conv2d(8,(3,3 ),activation='relu ',padding='same ' () encoded () ) ) ) ) ) ) ) )
x=upsampling 2d ((2,2 ) ) (x ) ) ) ) )。
x=conv2d(8,(3,3 ),activation='relu ',padding='same ' () (x ) ) ) ) ) ) ) ) )
x=upsampling 2d ((2,2 ) ) (x ) ) ) ) )。
x=conv2d(16,(3,3 ),activation=' relu ' (x ) ) ) ) ) ) ) ) )
x=upsampling 2d ((2,2 ) ) (x ) ) ) ) )。
编码=conv 2d (1,(3,3 ),活动=' sigmoid ',填充=' same ' ) x ) ) ) ) ) ) )
自动编码程序=模型(input _ shape,decoded ) )。
auto encoder.com pile (优化器=' ada delta ',loss='binary_crossentropy ' ) )
autoencoder.fit(X_train,x_train,
epochs=50,
batch_size=32,
shuffle=True,
validation_data=(X_test,x_test ),
callbacks=[ tensor board (log _ dir='/tmp/auto encoder ' ] )
Here:
x=conv2d(16,(3,3 ),activation='relu ',padding='same ' ) input_shape () ) ) ) ) ) )。
A shape is not a tensor。
Do this:
from keras.layers import *
输入tensor=输入(input _ shape )
x=conv2d(16,(3,3 ),activation='relu ',padding='same ' ) inputTensor () ) ) ) ) )。
youshouldseparatetheencoderanddecoderasindividualmodels.lateryouwillprobablywanttoworkwithonlyoneofthem。
Encoder:
输入tensor=输入(input _ shape )
x=.
编码模型=模型(输入传感器,编码数据)。
解码器:
编码输入=输入((4,4,8 ) )
x=.
解码器模型=模型((编码输入,解码数据) ) ) ) ) ) ) )。
自动编码器:
autoencoderinput=input (input _ shape )
编码=编码模型(autoencoderinput )
编码=编码模型(编码)。
autoencodermodel=model (autoencoderinput,已解码)。