2
$\begingroup$

Let's say I want to add a few hand-crafted features to a convolutional neural network CNN in TensorFlow.

The CNN can be a simple one as described here.

Naturally I'd like to add these features right after the second pooling and right before the first fully-connected layer (FC1 in the example).

Is that easy to express my method in code? I'd have to append my features to the h_pool2_flat vector/tensor:

h_pool2_flat = tf.reshape(h_pool2, [-1, 7*7*64])
h_fc1 = tf.nn.relu(tf.matmul(h_pool2_flat, W_fc1) + b_fc1)
$\endgroup$

2 Answers 2

2
$\begingroup$

I figured it out. If we denote the additional features as x_feat, I changed the lines from

h_pool2_flat = tf.reshape(h_pool2, [-1, 7*7*64])
h_fc1 = tf.nn.relu(tf.matmul(h_pool2_flat, W_fc1) + b_fc1)

to

h_pool2_flat = tf.reshape(h_pool2, [-1, 7*7*64])
h_pool2_flat = tf.concat( [h_pool2_flat, x_feat ], 1 )
h_fc1 = tf.nn.relu(tf.matmul(h_pool2_flat, W_fc1) + b_fc1)
$\endgroup$
0
$\begingroup$

One thing you can do is to replace the softmax layer by some other type of classifier, I'd recommend SVM. Thus, you feed the SVM with your handcrafted features concatenated with the output of the dense layer.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.