예제 #1
0
파일: rcnn.py 프로젝트: lartpang/luminoth
    def _instantiate_layers(self):
        """
        定义两个全连接层和后面的分类回归层
        :return: 无
        """

        # We define layers as an array since they are simple fully connected
        # ones and it should be easy to tune it from the network config.
        # 定义两个全连接层, layer_size表示输出通道数
        self._layers = [
            snt.Linear(
                layer_size,
                name='fc_{}'.format(i),
                initializers={'w': self._rcnn_initializer},
                regularizers={'w': self.regularizer},
            ) for i, layer_size in enumerate(self._layer_sizes)
        ]
        # We define the classifier layer having a num_classes + 1 background
        # since we want to be able to predict if the proposal is background as
        # well.
        # 定义一个分类的全连接层(21类)
        self._classifier_layer = snt.Linear(
            self._num_classes + 1,
            name='fc_classifier',
            initializers={'w': self._cls_initializer},
            regularizers={'w': self.regularizer},
        )

        # The bounding box adjustment layer has 4 times the number of classes
        # We choose which to use depending on the output of the classifier
        # layer
        # 输出通道数为类别数目x4, 也就是4x20, 每个类别对应4个值, 这个是独立于分类器的输出
        self._bbox_layer = snt.Linear(
            self._num_classes * 4,
            name='fc_bbox',
            initializers={'w': self._bbox_initializer},
            regularizers={'w': self.regularizer})

        # ROIPoolingLayer is used to extract the feature from the feature map
        # using the proposals.
        # self._config.roi表示的就是选择crop, 7x7, valid的池化配置
        self._roi_pool = ROIPoolingLayer(self._config.roi, debug=self._debug)
        # RCNNTarget is used to define a minibatch and the correct values for
        # each of the proposals.
        # 用来定义minibatch和提案的正确值
        self._rcnn_target = RCNNTarget(self._num_classes,
                                       self._config.target,
                                       variances=self._variances,
                                       seed=self._seed)
        # RCNNProposal generates the final bounding boxes and tries to remove
        # duplicates.
        self._rcnn_proposal = RCNNProposal(self._num_classes,
                                           self._config.proposals,
                                           variances=self._variances)
예제 #2
0
    def _instantiate_layers(self):
        # We define layers as an array since they are simple fully connected
        # ones and it should be easy to tune it from the network config.
        self._layers = [
            snt.Linear(
                layer_size,
                name="fc_{}".format(i),
                initializers={"w": self._rcnn_initializer},
                regularizers={"w": self.regularizer},
            )
            for i, layer_size in enumerate(self._layer_sizes)
        ]
        # We define the classifier layer having a num_classes + 1 background
        # since we want to be able to predict if the proposal is background as
        # well.
        self._classifier_layer = snt.Linear(
            self._num_classes + 1,
            name="fc_classifier",
            initializers={"w": self._cls_initializer},
            regularizers={"w": self.regularizer},
        )

        # The bounding box adjustment layer has 4 times the number of classes
        # We choose which to use depending on the output of the classifier
        # layer
        self._bbox_layer = snt.Linear(
            self._num_classes * 4,
            name="fc_bbox",
            initializers={"w": self._bbox_initializer},
            regularizers={"w": self.regularizer},
        )

        # ROIPoolingLayer is used to extract the feature from the feature map
        # using the proposals.
        self._roi_pool = ROIPoolingLayer(self._config.roi, debug=self._debug)
        # RCNNTarget is used to define a minibatch and the correct values for
        # each of the proposals.
        self._rcnn_target = RCNNTarget(
            self._num_classes,
            self._config.target,
            variances=self._variances,
            seed=self._seed,
        )
        # RCNNProposal generates the final bounding boxes and tries to remove
        # duplicates.
        self._rcnn_proposal = RCNNProposal(
            self._num_classes, self._config.proposals, variances=self._variances
        )
예제 #3
0
    def _run_roi_pooling(self, roi_proposals, pretrained, config):
        roi_proposals_tf = tf.placeholder(
            tf.float32, shape=roi_proposals.shape)
        pretrained_tf = tf.placeholder(tf.float32, shape=pretrained.shape)
        im_shape_tf = tf.placeholder(tf.float32, shape=(2,))

        model = ROIPoolingLayer(config, debug=True)
        results = model(roi_proposals_tf, pretrained_tf, im_shape_tf)

        with self.test_session() as sess:
            results = sess.run(results, feed_dict={
                roi_proposals_tf: roi_proposals,
                pretrained_tf: pretrained,
                im_shape_tf: self.im_shape,
            })
            return results