2017-11-28 41 views
1

このコメントは正しく取得できますか?私のモデルの5つの層は以下のようになっていますか?畳み込みニューラルネットワークのレイヤーを特定

この層内のモデル

# input - conv - conv - linear - linear(fc) 
    def model(data): # input Layer 

     # 1 conv Layer 
     conv = tf.nn.conv2d(data, layer1_weights, [1, 2, 2, 1], padding='SAME') 
     hidden = tf.nn.relu(conv + layer1_biases) # Activation function 

     # 1 conv Layer 
     conv = tf.nn.conv2d(hidden, layer2_weights, [1, 2, 2, 1], padding='SAME') 
     hidden = tf.nn.relu(conv + layer2_biases) # Activation function 

     # not a layer (just reshape) 
     shape = hidden.get_shape().as_list() 
     reshape = tf.reshape(hidden, [shape[0], shape[1] * shape[2] * shape[3]]) 

     # 1 linear layer - not fc due to relu 
     hidden = tf.nn.relu(tf.matmul(reshape, layer3_weights) + layer3_biases) 

     # 1 linear fully connected layer 
     return tf.matmul(hidden, layer4_weights) + layer4_biases 

答えて

1
# 1 linear layer - not fc due to relu 
    hidden = tf.nn.relu(tf.matmul(reshape, layer3_weights) + layer3_biases) 

は、それが完全に接続された層であり、それは「RELU」活性化機能を通過します。このコードの層は、この部分

tf.matmul(reshape, layer3_weights) + layer3_biases 

であり、あなたが

tf.nn.relu(tf.matmul(reshape, layer3_weights) + layer3_biases) 

その他、このすべてが罰金だrelu活性化機能によって、この層を送っています。

+0

私はそれを得ました。ありがとう! –

0

あなたのコメントラベルは正しいですが、あなたのコードに問題があると思います。

あなたがtf.nn.conv2dの定義を見てみると:[filter_height, filter_width, in_channels, out_channels]

あなたが代わりにtf.layers.conv2dを使用することもできます。

conv2d(
    input, 
    filter, 
    strides, 
    padding, 
    use_cudnn_on_gpu=True, 
    data_format='NHWC', 
    name=None 
) 

あなたは2番目の引数は重みではなく、として定義されたフィルタ(カーネル)形状は、ことを確認。コードを簡素化し、重み、バイアス、アクティブ化を1行で行います。例えば

conv1 = conv2d(data, filters, kernel_size=[2, 2], padding='same', activation=tf.nn.relu) 
+0

私はそれをチェックします。 良いヒント、ありがとう –

関連する問題