在 TensorFlow 中向卷积神经网络 (CNN) 添加手工制作的特征

数据挖掘 深度学习 张量流
2022-02-24 08:29:08

假设我想在 TensorFlow 中向卷积神经网络CNN添加一些手工制作的特征。

CNN 可以是一个简单的,如此所述。

当然,我想在第二个池之后和第一个全连接层(示例中的 FC1)之前添加这些功能。

用代码表达我的方法很容易吗?我必须将我的特征附加到h_pool2_flat向量/张量:

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)
2个回答

我想到了。如果我们将附加功能表示为x_feat,我将这些行从

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)

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)

您可以做的一件事是用其他类型的分类器替换 softmax 层,我推荐 SVM。因此,您可以将手工制作的特征与密集层的输出连接起来提供给 SVM。