DCGANでGeneratorを実装したのですが、関数を定義しないで書いたものと関数を定義したものでは出力結果が違ってしまいます。
関数を定義しないものでは<tf.Tensor 'Tanh_18:0' shape=(100, 64, 64, 3) dtype=float32>
ですが
関数を定義すると
<tf.Tensor 'Tanh_9:0' shape=(100, 8, 8, 256),dtype=float32>
と出力結果が違うのはなぜのでしょうか?
関数を定義しないもの
inputs = tf.random_uniform([100, 3], minval=-1.0, maxval=1.0) depths = [512, 256, 128, 64, 3] i_depth = depths[0:4] o_depth = depths[1:5] w0 = weight_variable([3, i_depth[0] * 4 * 4]) b0 = bias_variable([i_depth[0]]) dc0 = tf.nn.bias_add(tf.reshape(tf.matmul(inputs, w0), [-1, 4, 4, i_depth[0]]), b0) mean0, variance0 = tf.nn.moments(dc0, [0, 1, 2]) bn0 = tf.nn.batch_normalization(dc0, mean0, variance0, None, None, 1e-5) out = tf.nn.relu(bn0) #shape=(100, 4, 4, 512) # deconvolution layers for i in range(4): w = weight_variable([5, 5, o_depth[i], i_depth[i]]) b = bias_variable([o_depth[i]]) dc = tf.nn.conv2d_transpose(out, w, [100, 4 * 2 ** (i + 1), 4 * 2 ** (i + 1), o_depth[i]], [1, 2, 2, 1]) out = tf.nn.bias_add(dc, b) if i < 3: mean, variance = tf.nn.moments(out, [0, 1, 2]) out = tf.nn.relu(tf.nn.batch_normalization(out, mean, variance, None, None, 1e-5)) tf.nn.tanh(out) tf.nn.tanh(out) <tf.Tensor 'Tanh_18:0' shape=(100, 64, 64, 3) dtype=float32>
関数を定義したもの
def inference(inputs): depths = [512, 256, 128, 64, 3] i_depth = depths[0:4] o_depth = depths[1:5] w0 = weight_variable([3, i_depth[0] * 4 * 4]) b0 = bias_variable([i_depth[0]]) dc0 = tf.nn.bias_add(tf.reshape(tf.matmul(inputs, w0), [-1, 4, 4, i_depth[0]]), b0) mean0, variance0 = tf.nn.moments(dc0, [0, 1, 2]) bn0 = tf.nn.batch_normalization(dc0, mean0, variance0, None, None, 1e-5) out = tf.nn.relu(bn0) # deconvolution layers for i in range(4): w = weight_variable([5, 5, o_depth[i], i_depth[i]]) b = bias_variable([o_depth[i]]) dc = tf.nn.conv2d_transpose(out, w, [100, 4 * 2 ** (i + 1), 4 * 2 ** (i + 1), o_depth[i]], [1, 2, 2, 1]) out = tf.nn.bias_add(dc, b) if i < 3: mean, variance = tf.nn.moments(out, [0, 1, 2]) out = tf.nn.relu(tf.nn.batch_normalization(out, mean, variance, None, None, 1e-5)) return tf.nn.tanh(out) g= tf.placeholder(tf.float32, [None, 3]) inference(g) <tf.Tensor 'Tanh_9:0' shape=(100, 8, 8, 256) dtype=float32>
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/07/12 13:38