本文整理汇总了Python中TensorflowUtils.batch_norm方法的典型用法代码示例。如果您正苦于以下问题:Python TensorflowUtils.batch_norm方法的具体用法?Python TensorflowUtils.batch_norm怎么用?Python TensorflowUtils.batch_norm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TensorflowUtils
的用法示例。
在下文中一共展示了TensorflowUtils.batch_norm方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: generator
# 需要导入模块: import TensorflowUtils [as 别名]
# 或者: from TensorflowUtils import batch_norm [as 别名]
def generator(z, train_mode):
with tf.variable_scope("generator") as scope:
W_0 = utils.weight_variable([FLAGS.z_dim, 64 * GEN_DIMENSION / 2 * IMAGE_SIZE / 16 * IMAGE_SIZE / 16],
name="W_0")
b_0 = utils.bias_variable([64 * GEN_DIMENSION / 2 * IMAGE_SIZE / 16 * IMAGE_SIZE / 16], name="b_0")
z_0 = tf.matmul(z, W_0) + b_0
h_0 = tf.reshape(z_0, [-1, IMAGE_SIZE / 16, IMAGE_SIZE / 16, 64 * GEN_DIMENSION / 2])
h_bn0 = utils.batch_norm(h_0, 64 * GEN_DIMENSION / 2, train_mode, scope="gen_bn0")
h_relu0 = tf.nn.relu(h_bn0, name='relu0')
utils.add_activation_summary(h_relu0)
# W_1 = utils.weight_variable([5, 5, 64 * GEN_DIMENSION/2, 64 * GEN_DIMENSION], name="W_1")
# b_1 = utils.bias_variable([64 * GEN_DIMENSION/2], name="b_1")
# deconv_shape = tf.pack([tf.shape(h_relu0)[0], IMAGE_SIZE / 16, IMAGE_SIZE / 16, 64 * GEN_DIMENSION/2])
# h_conv_t1 = utils.conv2d_transpose_strided(h_relu0, W_1, b_1, output_shape=deconv_shape)
# h_bn1 = utils.batch_norm(h_conv_t1, 64 * GEN_DIMENSION/2, train_mode, scope="gen_bn1")
# h_relu1 = tf.nn.relu(h_bn1, name='relu1')
# utils.add_activation_summary(h_relu1)
W_2 = utils.weight_variable([5, 5, 64 * GEN_DIMENSION / 4, 64 * GEN_DIMENSION / 2],
name="W_2")
b_2 = utils.bias_variable([64 * GEN_DIMENSION / 4], name="b_2")
deconv_shape = tf.pack([tf.shape(h_relu0)[0], IMAGE_SIZE / 8, IMAGE_SIZE / 8, 64 * GEN_DIMENSION / 4])
h_conv_t2 = utils.conv2d_transpose_strided(h_relu0, W_2, b_2, output_shape=deconv_shape)
h_bn2 = utils.batch_norm(h_conv_t2, 64 * GEN_DIMENSION / 4, train_mode, scope="gen_bn2")
h_relu2 = tf.nn.relu(h_bn2, name='relu2')
utils.add_activation_summary(h_relu2)
W_3 = utils.weight_variable([5, 5, 64 * GEN_DIMENSION / 8, 64 * GEN_DIMENSION / 4],
name="W_3")
b_3 = utils.bias_variable([64 * GEN_DIMENSION / 8], name="b_3")
deconv_shape = tf.pack([tf.shape(h_relu2)[0], IMAGE_SIZE / 4, IMAGE_SIZE / 4, 64 * GEN_DIMENSION / 8])
h_conv_t3 = utils.conv2d_transpose_strided(h_relu2, W_3, b_3, output_shape=deconv_shape)
h_bn3 = utils.batch_norm(h_conv_t3, 64 * GEN_DIMENSION / 8, train_mode, scope="gen_bn3")
h_relu3 = tf.nn.relu(h_bn3, name='relu3')
utils.add_activation_summary(h_relu3)
W_4 = utils.weight_variable([5, 5, 64 * GEN_DIMENSION / 16, 64 * GEN_DIMENSION / 8],
name="W_4")
b_4 = utils.bias_variable([64 * GEN_DIMENSION / 16], name="b_4")
deconv_shape = tf.pack([tf.shape(h_relu3)[0], IMAGE_SIZE / 2, IMAGE_SIZE / 2, 64 * GEN_DIMENSION / 16])
h_conv_t4 = utils.conv2d_transpose_strided(h_relu3, W_4, b_4, output_shape=deconv_shape)
h_bn4 = utils.batch_norm(h_conv_t4, 64 * GEN_DIMENSION / 16, train_mode, scope="gen_bn4")
h_relu4 = tf.nn.relu(h_bn4, name='relu4')
utils.add_activation_summary(h_relu4)
W_5 = utils.weight_variable([5, 5, NUM_OF_CHANNELS, 64 * GEN_DIMENSION / 16], name="W_5")
b_5 = utils.bias_variable([NUM_OF_CHANNELS], name="b_5")
deconv_shape = tf.pack([tf.shape(h_relu4)[0], IMAGE_SIZE, IMAGE_SIZE, NUM_OF_CHANNELS])
h_conv_t5 = utils.conv2d_transpose_strided(h_relu4, W_5, b_5, output_shape=deconv_shape)
pred_image = tf.nn.tanh(h_conv_t5, name='pred_image')
utils.add_activation_summary(pred_image)
return pred_image
示例2: encoder
# 需要导入模块: import TensorflowUtils [as 别名]
# 或者: from TensorflowUtils import batch_norm [as 别名]
def encoder(dataset, train_mode):
with tf.variable_scope("Encoder"):
with tf.name_scope("enc_conv1") as scope:
W_conv1 = utils.weight_variable_xavier_initialized([3, 3, 3, 32], name="W_conv1")
b_conv1 = utils.bias_variable([32], name="b_conv1")
h_conv1 = utils.conv2d_strided(dataset, W_conv1, b_conv1)
h_bn1 = utils.batch_norm(h_conv1, 32, train_mode, scope="conv1_bn")
h_relu1 = tf.nn.relu(h_bn1)
with tf.name_scope("enc_conv2") as scope:
W_conv2 = utils.weight_variable_xavier_initialized([3, 3, 32, 64], name="W_conv2")
b_conv2 = utils.bias_variable([64], name="b_conv2")
h_conv2 = utils.conv2d_strided(h_relu1, W_conv2, b_conv2)
h_bn2 = utils.batch_norm(h_conv2, 64, train_mode, scope="conv2_bn")
h_relu2 = tf.nn.relu(h_bn2)
with tf.name_scope("enc_conv3") as scope:
W_conv3 = utils.weight_variable_xavier_initialized([3, 3, 64, 128], name="W_conv3")
b_conv3 = utils.bias_variable([128], name="b_conv3")
h_conv3 = utils.conv2d_strided(h_relu2, W_conv3, b_conv3)
h_bn3 = utils.batch_norm(h_conv3, 128, train_mode, scope="conv3_bn")
h_relu3 = tf.nn.relu(h_bn3)
with tf.name_scope("enc_conv4") as scope:
W_conv4 = utils.weight_variable_xavier_initialized([3, 3, 128, 256], name="W_conv4")
b_conv4 = utils.bias_variable([256], name="b_conv4")
h_conv4 = utils.conv2d_strided(h_relu3, W_conv4, b_conv4)
h_bn4 = utils.batch_norm(h_conv4, 256, train_mode, scope="conv4_bn")
h_relu4 = tf.nn.relu(h_bn4)
with tf.name_scope("enc_conv5") as scope:
W_conv5 = utils.weight_variable_xavier_initialized([3, 3, 256, 512], name="W_conv5")
b_conv5 = utils.bias_variable([512], name="b_conv5")
h_conv5 = utils.conv2d_strided(h_relu4, W_conv5, b_conv5)
h_bn5 = utils.batch_norm(h_conv5, 512, train_mode, scope="conv5_bn")
h_relu5 = tf.nn.relu(h_bn5)
with tf.name_scope("enc_fc") as scope:
image_size = IMAGE_SIZE // 32
h_relu5_flatten = tf.reshape(h_relu5, [-1, image_size * image_size * 512])
W_fc = utils.weight_variable([image_size * image_size * 512, 1024], name="W_fc")
b_fc = utils.bias_variable([1024], name="b_fc")
encoder_val = tf.matmul(h_relu5_flatten, W_fc) + b_fc
return encoder_val
示例3: inpainter
# 需要导入模块: import TensorflowUtils [as 别名]
# 或者: from TensorflowUtils import batch_norm [as 别名]
def inpainter(embedding, train_mode):
with tf.variable_scope("context_inpainter"):
image_size = IMAGE_SIZE // 32
with tf.name_scope("dec_fc") as scope:
W_fc = utils.weight_variable([1024, image_size * image_size * 512], name="W_fc")
b_fc = utils.bias_variable([image_size * image_size * 512], name="b_fc")
h_fc = tf.nn.relu(tf.matmul(embedding, W_fc) + b_fc)
with tf.name_scope("dec_conv1") as scope:
h_reshaped = tf.reshape(h_fc, tf.pack([tf.shape(h_fc)[0], image_size, image_size, 512]))
W_conv_t1 = utils.weight_variable_xavier_initialized([3, 3, 256, 512], name="W_conv_t1")
b_conv_t1 = utils.bias_variable([256], name="b_conv_t1")
deconv_shape = tf.pack([tf.shape(h_reshaped)[0], 2 * image_size, 2 * image_size, 256])
h_conv_t1 = utils.conv2d_transpose_strided(h_reshaped, W_conv_t1, b_conv_t1, output_shape=deconv_shape)
h_bn_t1 = utils.batch_norm(h_conv_t1, 256, train_mode, scope="conv_t1_bn")
h_relu_t1 = tf.nn.relu(h_bn_t1)
with tf.name_scope("dec_conv2") as scope:
W_conv_t2 = utils.weight_variable_xavier_initialized([3, 3, 128, 256], name="W_conv_t2")
b_conv_t2 = utils.bias_variable([128], name="b_conv_t2")
deconv_shape = tf.pack([tf.shape(h_relu_t1)[0], 4 * image_size, 4 * image_size, 128])
h_conv_t2 = utils.conv2d_transpose_strided(h_relu_t1, W_conv_t2, b_conv_t2, output_shape=deconv_shape)
h_bn_t2 = utils.batch_norm(h_conv_t2, 128, train_mode, scope="conv_t2_bn")
h_relu_t2 = tf.nn.relu(h_bn_t2)
with tf.name_scope("dec_conv3") as scope:
W_conv_t3 = utils.weight_variable_xavier_initialized([3, 3, 64, 128], name="W_conv_t3")
b_conv_t3 = utils.bias_variable([64], name="b_conv_t3")
deconv_shape = tf.pack([tf.shape(h_relu_t2)[0], 8 * image_size, 8 * image_size, 64])
h_conv_t3 = utils.conv2d_transpose_strided(h_relu_t2, W_conv_t3, b_conv_t3, output_shape=deconv_shape)
h_bn_t3 = utils.batch_norm(h_conv_t3, 64, train_mode, scope="conv_t3_bn")
h_relu_t3 = tf.nn.relu(h_bn_t3)
with tf.name_scope("dec_conv4") as scope:
W_conv_t4 = utils.weight_variable_xavier_initialized([3, 3, 3, 64], name="W_conv_t4")
b_conv_t4 = utils.bias_variable([3], name="b_conv_t4")
deconv_shape = tf.pack([tf.shape(h_relu_t3)[0], 16 * image_size, 16 * image_size, 3])
pred_image = utils.conv2d_transpose_strided(h_relu_t3, W_conv_t4, b_conv_t4, output_shape=deconv_shape)
return pred_image
示例4: discriminator
# 需要导入模块: import TensorflowUtils [as 别名]
# 或者: from TensorflowUtils import batch_norm [as 别名]
def discriminator(input_images, train_mode):
# dropout_prob = 1.0
# if train_mode:
# dropout_prob = 0.5
W_conv0 = utils.weight_variable([5, 5, NUM_OF_CHANNELS, 64 * 1], name="W_conv0")
b_conv0 = utils.bias_variable([64 * 1], name="b_conv0")
h_conv0 = utils.conv2d_strided(input_images, W_conv0, b_conv0)
h_bn0 = h_conv0 # utils.batch_norm(h_conv0, 64 * 1, train_mode, scope="disc_bn0")
h_relu0 = utils.leaky_relu(h_bn0, 0.2, name="h_relu0")
utils.add_activation_summary(h_relu0)
W_conv1 = utils.weight_variable([5, 5, 64 * 1, 64 * 2], name="W_conv1")
b_conv1 = utils.bias_variable([64 * 2], name="b_conv1")
h_conv1 = utils.conv2d_strided(h_relu0, W_conv1, b_conv1)
h_bn1 = utils.batch_norm(h_conv1, 64 * 2, train_mode, scope="disc_bn1")
h_relu1 = utils.leaky_relu(h_bn1, 0.2, name="h_relu1")
utils.add_activation_summary(h_relu1)
W_conv2 = utils.weight_variable([5, 5, 64 * 2, 64 * 4], name="W_conv2")
b_conv2 = utils.bias_variable([64 * 4], name="b_conv2")
h_conv2 = utils.conv2d_strided(h_relu1, W_conv2, b_conv2)
h_bn2 = utils.batch_norm(h_conv2, 64 * 4, train_mode, scope="disc_bn2")
h_relu2 = utils.leaky_relu(h_bn2, 0.2, name="h_relu2")
utils.add_activation_summary(h_relu2)
W_conv3 = utils.weight_variable([5, 5, 64 * 4, 64 * 8], name="W_conv3")
b_conv3 = utils.bias_variable([64 * 8], name="b_conv3")
h_conv3 = utils.conv2d_strided(h_relu2, W_conv3, b_conv3)
h_bn3 = utils.batch_norm(h_conv3, 64 * 8, train_mode, scope="disc_bn3")
h_relu3 = utils.leaky_relu(h_bn3, 0.2, name="h_relu3")
utils.add_activation_summary(h_relu3)
shape = h_relu3.get_shape().as_list()
h_3 = tf.reshape(h_relu3, [FLAGS.batch_size, (IMAGE_SIZE // 16) * (IMAGE_SIZE // 16) * shape[3]])
W_4 = utils.weight_variable([h_3.get_shape().as_list()[1], 1], name="W_4")
b_4 = utils.bias_variable([1], name="b_4")
h_4 = tf.matmul(h_3, W_4) + b_4
return tf.nn.sigmoid(h_4), h_4, h_relu3