什么?AI黑白图像能够自动上色?( 五 )


out_channelsstride=stride) normalized=batchnorm(convolved) rectified=lrelu(normalized 0.2 ) layers.append(rectified) #layer_5:[batch 31 31 ndf* 8
=[batch 30 30 1
with tf.variable_scope( \"layer_%d\" %(len(layers)+ 1 )): convolved=discrim_conv(rectifiedout_channels= 1 stride= 1 ) output=tf.sigmoid(convolved) layers.append(output) return layers[ -1
with tf.variable_scope( \"generator\" ): out_channels= int (targets.get_shape()[ -1
) outputs=create_generator(inputsout_channels) #createtwocopiesofdiscriminatorone for realpairsandone for fakepairs #theysharethesameunderlyingvariables with tf.name_scope( \"real_discriminator\" ): with tf.variable_scope( \"discriminator\" ): # 2 x[batchheightwidthchannels
=[batch 30 30 1
predict_real=create_discriminator(inputstargets) with tf.name_scope( \"fake_discriminator\" ): with tf.variable_scope( \"discriminator\" reuse=True): # 2 x[batchheightwidthchannels
=[batch 30 30 1
predict_fake=create_discriminator(inputsoutputs) with tf.name_scope( \"discriminator_loss\" ): #minimizing-tf.logwill try to get inputsto 1 #predict_real= 1 #predict_fake= 0 discrim_loss=tf.reduce_mean(-(tf.log(predict_real+EPS)+tf.log( 1 -predict_fake+EPS))) with tf.name_scope( \"generator_loss\" ): #predict_fake= 1 #abs(targets-outputs)= 0 gen_loss_GAN=tf.reduce_mean(-tf.log(predict_fake+EPS)) gen_loss_L1=tf.reduce_mean(tf.abs(targets-outputs)) gen_loss=gen_loss_GAN*a.gan_weight+gen_loss_L1*a.l1_weight with tf.name_scope( \"discriminator_train\" ): discrim_tvars=[ var for var in tf.trainable_variables() if var .name.startswith( \"discriminator\" )

推荐阅读