简体   繁体   English

如何使用Tensorflow在卷积网络中的完全连接层之后添加回归头?

[英]How to add a regression head after the fully connected layer in convolutional network using Tensorflow?

I am new to deep learning and Tensorflow and have to learn this topic due to a project I am currently working on. 我是深度学习和Tensorflow的新手,由于我正在进行的项目,我不得不学习这个主题。 I am using convolutional network to detect and find the location of a single object in the image. 我正在使用卷积网络来检测和查找图像中单个对象的位置。 I am using the method introduced in Standford CS231n class . 我正在使用Standford CS231n类中引入的方法。 The lecturer mentioned about connecting a regression head after the fully connected layer in the network to find the location of the object. 讲师提到了在网络中完全连接的层之后连接回归头以找到对象的位置。 I know there is DNNRegressor in Tensorflow. 我知道DNNRegressor中有DNNRegressor。 Should I use this as the regression head? 我应该用它作为回归头吗?

Before I modified Tensorflow's tutorial on using ConvNet to recognize handwritten digit for my case. 在我修改Tensorflow关于使用ConvNet来识别我的案例的手写数字的教程之前。 I am not too sure how can I add the regression head to that program so that it can also find a bounding box for the object. 我不太确定如何将回归头添加到该程序,以便它还可以找到该对象的边界框。

I just had the chance to touch machine learning and deep learning this week, apology if I asked a really silly question, but I really need to find a solution to my problem. 本周我有机会接触机器学习和深度学习,如果我问了一个非常愚蠢的问题,道歉,但我真的需要找到解决问题的方法。 Thank you very much. 非常感谢你。

First of all, in order to train a neural network for object localization task, you have to have a data set with localized objects. 首先,为了训练神经网络进行对象定位任务,你必须拥有一个带有本地化对象的数据集。 This answers your question whether you can work with MNIST data set or not. 这回答了您是否可以使用MNIST数据集的问题。 MNIST contains just a class label for each image, so you need to get another data set . MNIST只包含每个图像的类标签,因此您需要获取另一个数据集 Justin also talks about popular data sets at around 37:34. 贾斯汀还在 37:34左右谈论了流行的数据集。

The way object localization works is by learning to output 4 values per image, instead of class distribution. 对象本地化的工作方式是学习每个图像输出4个值,而不是类分布。 This four-valued vector is compared to the ground truth four-valued vector and the loss function is usually L1 or L2 norm of their difference. 将该四值向量与地面实况四值向量进行比较,并且损失函数通常是它们的差值的L1或L2范数。 So in code, regression head is an ordinary regression layer, which can be implemented in tensorflow by a simple tf.reduce_mean call. 因此在代码中, 回归头是一个普通的回归层,可以通过简单的tf.reduce_mean调用在tensorflow中实现。

A small yet complete example that performs object localization can be found here . 可以在此处找到执行对象本地化的小而完整的示例。 Also recommend to take a look at this question . 还建议看一下这个问题

I was looking for this problem as well and I found the following part in the document . 我也在寻找这个问题,我在文档中找到了以下部分。

Dense (fully connected) layers, which perform classification on the features extracted by the convolutional layers and downsampled by the pooling layers. 密集(完全连接)层,对卷积层提取的特征进行分类,并由池化层进行下采样。 In a dense layer, every node in the layer is connected to every node in the preceding layer. 在密集层中,层中的每个节点都连接到前一层中的每个节点。

Based on this quote, it seems you can't do regression but classification . 根据这个引用, 似乎你不能做回归而是分类

EDIT: After some research, I found out a way to use a fully-connected layer in tensorflow . 编辑:经过一些研究,我发现了一种在tensorflow使用fully-connected层的tensorflow

import tensorflow.contrib.slim as slim

#create your network **net**. 

#In the last step, you should use 
y_prime = slim.fully_connected(net, 1, activation_fn=None, reuse=reuse)

loss = tf.reduce_mean(tf.square(y_prime - y)) #L2 norm
lr = tf.placeholder(tf.float32)
opt = tf.train.AdamOptimizer(learning_rate=lr).minimize(loss)

You can add more fully connected layers before the last step which can have more nodes. 您可以在最后一步之前添加更多fully connected图层,这可以包含更多节点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Tensorflow池化层如何连接到卷积层 - Tensorflow how pooling layer is connected to convolutional layer 卷积生成对抗网络判别器的output是如何工作的,可以有全连接层吗? - How does the output of the Discriminator of a Convolutional Generative Adversarial Network work, can it have a Fully Connected Layer? 张量流中未完全连接的层 - Not fully connected layer in tensorflow 使用Tensorflow中的MNIST上的一个隐藏层来训练完全连接的网络 - Training a fully connected network with one hidden layer on MNIST in Tensorflow 如何将不同形状的卷积层输出合并为固定形状以传递给全连接层 - how to pool different shaped convolutional layer outputs to a fixed shape to pass for Fully connected layer TensorFlow(全卷积网络)中的 FCN-8 解码器 - FCN-8 decoder in TensorFlow (Fully Convolutional Network) 我可以将卷积神经网络视为完全连接的神经网络吗 - Can I view convolutional neural network as fully connected neural network 神经网络中密集(全连接)层的使用 - Usage of Dense(Fully Connected) Layer in Neural Network 如何添加回归头 - How to Add a Regression Head 如何使用截断的SVD减少完全连接(“InnerProduct”)层 - How to reduce a fully-connected (`“InnerProduct”`) layer using truncated SVD
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM