2
votes

I am new in the computer vision and ML. After several exiting weeks with Python and TensorFlow I have some questions.

How to convert trained convolutional network (CNN) to use it as a detector? (get a heatmap)

For ex.:

We have

trained MNIST model

MODEL = [None, 28**2] > [CONV3+POOL] > [CONV3+POOL] > [DENSELAYER] > [None, 10]

I want:

[None, WH] > [MODEL] > [None, w, h, 10]

I read that to do so it is necessary to convert the [DENSELAYER] into convolution. Am i right?

Thank you in advance for your help and sorry for my english :) the old code looks like this:

    with tf.name_scope('dense_layer'):
        dense1 = tf.reshape(conv2, [-1, _weights['wd1'].get_shape().as_list()[0]])
        dense1 = tf.nn.relu(tf.matmul(dense1, _weights['wd1']) + _biases['bd1'])
        dense1 = tf.nn.dropout(dense1, dropout)
        out = tf.nn.softmax(tf.matmul(dense1, _weights['out']) + _biases['out'])
    return out

I think the first fully connected layer should be a 7x7 conv, but I'm not sure how to handle the second fc layer (the output layer):

    with tf.name_scope('conv_layer_3'):
        # ?????
        wc3 = tf.reshape(_weights['wd1'], [7, 7, w2, d1])
        conv3 = conv2d_valid(conv2, wc3, _biases['bd1'])
    with tf.name_scope('conv_layer_4'):
        # ???
    return out
1

1 Answers

4
votes

Yes. Reshaping the first FC layer to 7x7 is what you want. For the output layer what you're looking for is a 1x1 convolution, which basically runs the fully connected output layer on each pixel.

wc4 = tf.reshape(_weights['out'], [1, 1, d1, out])
conv4 = conv2d_valid(conv3, wc4, _biases['out'])