gpt4 book ai didi

python - 如何将经过训练的卷积网络 (CNN) 转换为用作检测器?

转载 作者:行者123 更新时间:2023-11-28 22:39:11 27 4
gpt4 key购买 nike

我是计算机视觉和机器学习领域的新手。在使用 Python 和 TensorFlow 几周后,我有一些问题。

如何将经过训练的卷积网络 (CNN) 转换为将其用作检测器? (获取热图)

例如:

我们有

训练好的 MNIST 模型

模型 = [无,28**2] > [CONV3+POOL] > [CONV3+POOL] > [DENSELAYER] > [无,10]

我要:

[无,WH] > [模型] > [无,w,h,10]

我读到有必要将 [DENSELAYER] 转换为卷积。我说得对吗?

预先感谢您的帮助,抱歉我的英语不好 :) 旧代码如下所示:

    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

我认为第一个全连接层应该是一个 7x7 conv,但我不确定如何处理第二个 fc 层(输出层):

    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

最佳答案

是的。将第一个 FC 层 reshape 为 7x7 就是你想要的。对于输出层,您正在寻找的是 1x1 convolution ,它基本上在每个像素上运行完全连接的输出层。

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

关于python - 如何将经过训练的卷积网络 (CNN) 转换为用作检测器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34972881/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com