我有两种不同类型的图像(相机图像和相应的草图)。该网络的目标是找到两张图像之间的相似性。
该网络由一个编码器和一个解码器组成。单个编码器-解码器背后的动机是在它们之间共享权重。
input_img = Input(shape=(img_width,img_height, channels))
def encoder(input_img):
# Photo-Encoder Code
pe = Conv2D(96, kernel_size=11, strides=(4,4), padding = 'SAME')(left_input) # (?, 64, 64, 96)
pe = BatchNormalization()(pe)
pe = Activation('selu')(pe)
pe = MaxPool2D((3, 3), strides=(2, 2), padding = 'VALID')(pe) # (?, 31, 31, 96)
pe = Conv2D(256, kernel_size=5, strides=(1,1), padding = 'SAME')(pe) # (?, 31, 31, 256)
pe = BatchNormalization()(pe)
pe = Activation('selu')(pe)
pe = MaxPool2D((3, 3), strides=(2, 2), padding = 'VALID')(pe) #(?, 15, 15, 256)
pe = Conv2D(384, kernel_size=3, strides=(1,1), padding = 'SAME')(pe) # (?, 15, 15, 384)
pe = BatchNormalization()(pe)
pe = Activation('selu')(pe)
pe = Conv2D(384, kernel_size=3, strides=(1,1), padding = 'SAME')(pe) # (?, 15, 15, 384)
pe = BatchNormalization()(pe)
pe = Activation('selu')(pe)
pe = Conv2D(256, kernel_size=3, strides=(1,1), padding = 'SAME')(pe) # (?, 15, 15, 256)
pe = BatchNormalization()(pe)
pe = Activation('selu')(pe)
encoded = MaxPool2D((3, 3), strides=(2, 2), padding = 'VALID')(pe) # (?, 7, 7, 256)
return encoded
def decoder(pe):
pe = Conv2D(1024, kernel_size=7, strides=(1, 1), padding = 'VALID')(pe)
pe = BatchNormalization()(pe)
pe = Activation('selu')(pe)
p_decoder_inp = Reshape((2,2,256))(pe)
pd = Conv2DTranspose(128, kernel_size=5, strides=(2, 2), padding='SAME')(p_decoder_inp)
pd = Activation("selu")(pd)
pd = Conv2DTranspose(64, kernel_size=5, strides=(2, 2), padding='SAME')(pd)
pd = Activation("selu")(pd)
pd = Conv2DTranspose(32, kernel_size=5, strides=(2, 2), padding='SAME')(pd)
pd = Activation("selu")(pd)
pd = Conv2DTranspose(16, kernel_size=5, strides=(2, 2), padding='SAME')(pd)
pd = Activation("selu")(pd)
pd = Conv2DTranspose(8, kernel_size=5, strides=(2, 2), padding='SAME')(pd)
pd = Activation("selu")(pd)
pd = Conv2DTranspose(4, kernel_size=5, strides=(2, 2), padding='SAME')(pd)
pd = Activation("selu")(pd)
decoded = Conv2DTranspose(3, kernel_size=5, strides=(2, 2), padding='SAME', activation='sigmoid')(pd) # (?, ?, ?, 3)
return decoded
siamsese_net = Model([camera_img, sketch_img], [decoder(encoder(camera_img)), decoder(encoder(sketch_img))])
siamsese_net.summary()
当我可视化网络时,它显示了两个不同的网络。
但我想要的是一个网络,它接受两个输入,例如,相机图像和草图图像,并使用单个编码器 - 解码器返回相同的图像。
我在哪里做错了?