python substract_Python layers.Subtract方法代码示例

该博客介绍了如何在Python中利用Keras库的Subtract层来构建一个判别器模型。首先导入必要的模块,然后定义两个输入,通过Multiply层将图像和分割图相结合,接着使用Encoder对结合后的输入进行处理。随后,通过Subtract层计算两组编码输出的差值,并通过一系列的卷积和池化操作进行特征提取,最终得到用于相似度判断的输出。模型使用Adadelta优化器,损失函数为二元交叉熵,评估指标为准确性。
摘要由CSDN通过智能技术生成

# 需要导入模块: from keras import layers [as 别名]

# 或者: from keras.layers import Subtract [as 别名]

def get_Discriminator(input_shape_1, input_shape_2, Encoder):

dis_inputs_1 = Input(shape=input_shape_1) # Image

dis_inputs_2 = Input(shape=input_shape_2) # Segmentation

mul_1 = Multiply()([dis_inputs_1, dis_inputs_2]) # Getting segmented part

encoder_output_1 = Encoder(dis_inputs_1)

encoder_output_2 = Encoder(mul_1)

subtract_dis = Subtract()([encoder_output_1, encoder_output_2])

dis_conv_block = Conv3D(128, (3, 3, 3), strides=(1, 1, 1), padding='same')(subtract_dis)

dis_conv_block = Activation('relu')(dis_conv_block)

dis_conv_block = Conv3D(128, (3, 3, 3), strides=(1, 1, 1), padding='same')(dis_conv_block)

dis_conv_block = Activation('relu')(dis_conv_block)

dis_conv_block = MaxPooling3D(pool_size=(2, 2, 2), strides=(2, 2, 2))(dis_conv_block)

dis_conv_block = Conv3D(64, (3, 3, 3), strides=(1, 1, 1), padding='same')(dis_conv_block)

dis_conv_block = Activation('relu')(dis_conv_block)

dis_conv_block = Conv3D(64, (3, 3, 3), strides=(1, 1, 1), padding='same')(dis_conv_block)

dis_conv_block = Activation('relu')(dis_conv_block)

dis_conv_block = Conv3D(32, (3, 3, 3), strides=(1, 1, 1), padding='same')(dis_conv_block)

dis_conv_block = Activation('relu')(dis_conv_block)

dis_conv_block = Conv3D(32, (3, 3, 3), strides=(1, 1, 1), padding='same')(dis_conv_block)

dis_conv_block = Activation('relu')(dis_conv_block)

flat_1 = Flatten()(dis_conv_block)

dis_fc_1 = Dense(256)(flat_1)

dis_fc_1 = Activation('relu')(dis_fc_1)

dis_drp_1 = Dropout(0.5)(dis_fc_1)

dis_fc_2 = Dense(128)(dis_drp_1)

dis_fc_2 = Activation('relu')(dis_fc_2)

dis_drp_2 = Dropout(0.5)(dis_fc_2)

dis_fc_3 = Dense(1)(dis_drp_2)

dis_similarity_output = Activation('sigmoid')(dis_fc_3)

Discriminator = Model(inputs=[dis_inputs_1, dis_inputs_2], outputs=dis_similarity_output)

Discriminator.compile(optimizer=Adadelta(lr=0.01), loss='binary_crossentropy', metrics=['accuracy'])

print('Discriminator Architecture:')

print(Discriminator.summary())

return Discriminator

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值