识别卷积神经网络的各个层

时间:2017-11-28 16:27:46

标签: python tensorflow conv-neural-network

我的评论是否正确?这些是我模型的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

2 个答案:

答案 0 :(得分: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

并且您通过relu激活函数发送此图层

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

其他这一切似乎都很好。

答案 1 :(得分:0)

您的评论标签是正确的,但我认为您的代码存在问题。

如果你看一下tf.nn.conv2d的定义:

    public void run()
    {
        List<Thread> lst = new List<Thread>();
        for (int i = 0; i < 10; i++)
        {
            Thread t = new Thread(() => print_me(i));
            lst.Add(t);                
        }

        foreach (Thread t in lst )
            t.Start();
    }
    void print_me(int num)
    {
        Debug.WriteLine(num);
    }

您看到第二个参数不是权重,而是过滤器(内核)形状,定义为:conv2d( input, filter, strides, padding, use_cudnn_on_gpu=True, data_format='NHWC', name=None )

您可以使用tf.layers.conv2d代替。它简化了代码,并在一行中进行权重,偏差和激活。 e.g。

[filter_height, filter_width, in_channels, out_channels]
相关问题