官术网_书友最值得收藏!

The discriminator network

Similarly, to implement the discriminator network, we need to create a Keras model and add the neural network layers to it. The steps required to implement the discriminator network are as follows:

  1. Start by specifying the values for different hyperparameters:
dis_input_shape = (64, 64, 64, 1)
dis_filters = [64, 128, 256, 512, 1]
dis_kernel_sizes = [4, 4, 4, 4, 4]
dis_strides = [2, 2, 2, 2, 1]
dis_paddings = ['same', 'same', 'same', 'same', 'valid']
dis_alphas = [0.2, 0.2, 0.2, 0.2, 0.2]
dis_activations = ['leaky_relu', 'leaky_relu', 'leaky_relu', 'leaky_relu', 'sigmoid']
dis_convolutional_blocks = 5

  1. Next, create an input layer to allow the network to take input. The input to the discriminator network is a 3D image that has a shape of 64x64x64x1:
dis_input_layer = Input(shape=dis_input_shape)
  1. Then, add the first 3D convolution block, shown as follows:
# The first 3D Convolution block
a = Conv3D(filters=dis_filters[0],
kernel_size=dis_kernel_sizes[0],
strides=dis_strides[0],
padding=dis_paddings[0])(dis_input_layer)
a = BatchNormalization()(a, training=True)
a = LeakyReLU(alphas[0])(a)
  1. After that, add four more 3D convolution blocks, shown as follows:
# The next 4 3D Convolutional Blocks
for i in range(dis_convolutional_blocks - 1):
a = Conv3D(filters=dis_filters[i + 1],
kernel_size=dis_kernel_sizes[i + 1],
strides=dis_strides[i + 1],
padding=dis_paddings[i + 1])(a)
a = BatchNormalization()(a, training=True)
if dis_activations[i + 1] == 'leaky_relu':
a = LeakyReLU(dis_alphas[i + 1])(a)
elif dis_activations[i + 1] == 'sigmoid':
a = Activation(activation='sigmoid')(a)
  1. Next, create a Keras model and specify the inputs and the outputs for the discriminator network:
dis_model = Model(inputs=dis_input_layer, outputs=a)
  1. Wrap the complete code for the discriminator network inside a function, given as follows:
def build_discriminator():
"""
Create a Discriminator Model using hyperparameters values defined as follows
:return: Discriminator network
"""

dis_input_shape = (64, 64, 64, 1)
dis_filters = [64, 128, 256, 512, 1]
dis_kernel_sizes = [4, 4, 4, 4, 4]
dis_strides = [2, 2, 2, 2, 1]
dis_paddings = ['same', 'same', 'same', 'same', 'valid']
dis_alphas = [0.2, 0.2, 0.2, 0.2, 0.2]
dis_activations = ['leaky_relu', 'leaky_relu', 'leaky_relu',
'leaky_relu', 'sigmoid']
dis_convolutional_blocks = 5

dis_input_layer = Input(shape=dis_input_shape)

# The first 3D Convolutional block
a = Conv3D(filters=dis_filters[0],
kernel_size=dis_kernel_sizes[0],
strides=dis_strides[0],
padding=dis_paddings[0])(dis_input_layer)
a = BatchNormalization()(a, training=True)
a = LeakyReLU(dis_alphas[0])(a)

# Next 4 3D Convolutional Blocks
for i in range(dis_convolutional_blocks - 1):
a = Conv3D(filters=dis_filters[i + 1],
kernel_size=dis_kernel_sizes[i + 1],
strides=dis_strides[i + 1],
padding=dis_paddings[i + 1])(a)
a = BatchNormalization()(a, training=True)
if dis_activations[i + 1] == 'leaky_relu':
a = LeakyReLU(dis_alphas[i + 1])(a)
elif dis_activations[i + 1] == 'sigmoid':
a = Activation(activation='sigmoid')(a)

dis_model = Model(inputs=dis_input_layer, outputs=a)
print(dis_model.summary())
return dis_model

In this section, we created a Keras model for the discriminator network. We are now ready to train a 3D-GAN.

主站蜘蛛池模板: 漠河县| 武陟县| 分宜县| 辽阳县| 平安县| 彰武县| 上栗县| 望江县| 涡阳县| 象山县| 嵊州市| 华容县| 阿合奇县| 武安市| 荥经县| 乳源| 惠州市| 宁津县| 鹰潭市| 土默特右旗| 健康| 三穗县| 和顺县| 兴宁市| 越西县| 云林县| 安图县| 板桥市| 绥化市| 仪征市| 洞口县| 车致| 象山县| 阳山县| 孙吴县| 四子王旗| 桃源县| 玉林市| 隆安县| 凯里市| 东宁县|