# Adding hand-crafted features to a convolutional neural network (CNN) in TensorFlow

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)


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)


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.