示例#1
0
    def build(self):

        # 提取特征,属于公共部分
        block1, block2, block3, block4 = self._feature(self.input_data)
        blocks = [block1, block2, block3, block4]
        block4_shape = Tools.get_shape(block4)  # 45, 512
        block3_shape = Tools.get_shape(block3)  # 90, 512
        block2_shape = Tools.get_shape(block2)  # 180, 256
        block1_shape = Tools.get_shape(block1)  # 360, 128

        segments = []
        segments_output = []

        ######################################################
        # 确定初始attention的输入点:建议在进入attention时输入
        ######################################################

        with tf.variable_scope(name_or_scope="attention_4"):
            net_output = self._decoder(block4, block4_shape, block3_shape, name="4")
            net_segment_output = self._segment(block4, block4_shape, block3_shape, name="segment_side_4")
            segments.append(net_segment_output)  # segment
            pass

        segments_output.append(net_output)
        block3_add = Net.add([block3, net_output], name='attention_3_add')
        with tf.variable_scope(name_or_scope="attention_3"):
            net_output = self._decoder(block3_add, block3_shape, block2_shape, name="3")
            net_segment_output = self._segment(block3_add, block3_shape, block2_shape, name="segment_side_3")
            segments.append(net_segment_output)  # segment
            pass

        segments_output.append(net_output)
        block2_add = Net.add([block2, net_output], name="attention_2_net_output_relu")
        with tf.variable_scope(name_or_scope="attention_2"):
            net_output = self._decoder(block2_add, block2_shape, block1_shape, name="2")
            net_segment_output = self._segment(block2_add, block2_shape, block1_shape, name="segment_side_2")
            segments.append(net_segment_output)  # segment
            pass

        segments_output.append(net_output)
        block1_add = Net.add([block1, net_output], name="attention_1_concat")
        with tf.variable_scope(name_or_scope="attention_1"):
            net_output = self._decoder(block1_add, block1_shape, block1_shape, name="1")
            net_segment_output = self._segment(block1_add, block1_shape, block1_shape, name="segment_side_1")
            segments.append(net_segment_output)  # segment
            pass

        segments_output.append(net_output)
        net_output = Net.conv(net_output, 3, 3, self.num_classes, 1, 1,
                              biased=True, relu=False, name='attention_0_21')
        segments.append(net_output)  # segment

        features = {"block": blocks, "segment": segments_output}
        return segments, features
示例#2
0
    def build(self):

        # 提取特征,属于公共部分
        block1, block2, block3, block4 = self._feature(self.input_data)
        block4_shape = Tools.get_shape(block4)  # 45, 512
        block3_shape = Tools.get_shape(block3)  # 90, 512
        block2_shape = Tools.get_shape(block2)  # 180, 256
        block1_shape = Tools.get_shape(block1)  # 360, 128

        segments = []

        ######################################################
        # 确定初始attention的输入点:建议在进入attention时输入
        ######################################################

        with tf.variable_scope(name_or_scope="attention_4"):
            net_output = self._decoder(block4, block4_shape, block3_shape, name="4")
            pass

        block3_add = Net.add([block3, net_output], name='attention_3_add')
        with tf.variable_scope(name_or_scope="attention_3"):
            net_output = self._decoder(block3_add, block3_shape, block2_shape, name="3")
            pass

        block2_add = Net.add([block2, net_output], name="attention_2_net_output_relu")
        with tf.variable_scope(name_or_scope="attention_2"):
            net_output = self._decoder(block2_add, block2_shape, block1_shape, name="2")
            pass

        block1_add = Net.add([block1, net_output], name="attention_1_concat")
        with tf.variable_scope(name_or_scope="attention_1"):
            net_output = self._decoder(block1_add, block1_shape, block1_shape, name="1")
            pass

        net_output = Net.conv(net_output, 3, 3, 2, 1, 1, biased=True, relu=False, name='attention_0')
        segments.append(net_output)  # segment
        return segments
    def build_old(self):

        # 提取特征,属于公共部分
        block1, block2, block3, block4 = self._feature(self.input_data)
        blocks = [block1, block2, block3, block4]
        block4_shape = Tools.get_shape(block4)  # 45, 512
        block3_shape = Tools.get_shape(block3)  # 90, 512
        block2_shape = Tools.get_shape(block2)  # 180, 256
        block1_shape = Tools.get_shape(block1)  # 360, 128

        adds = []
        adds_in_block = []
        adds_in_2 = []
        adds = []
        temps = []
        segments = []
        segments_output = []

        ######################################################
        # 确定初始attention的输入点:建议在进入attention时输入
        ######################################################

        with tf.variable_scope(name_or_scope="attention_4"):
            # 0
            net_segment_output, temp = self._segment(block4,
                                                     block4_shape,
                                                     block3_shape,
                                                     name="segment_side_4")
            temps.append(temp)
            segments.append(net_segment_output)  # segment

            net_output = self._decoder(block4,
                                       block4_shape,
                                       block3_shape,
                                       name="4")
            segments_output.append(net_output)
            pass

        with tf.variable_scope(name_or_scope="attention_3"):
            # 1  ==>
            # net_segment_block_output, temp = self._segment(block3, block3_shape, block2_shape, name="segment_side_3_block")
            # temps.append(temp)
            # segments.append(net_segment_block_output)  # segment

            # 2
            block3_add = Net.add([block3, net_output], name='add')
            adds_in_block.append(block3)
            adds_in_2.append(net_output)
            adds.append(block3_add)

            net_segment_output, temp = self._segment(block3_add,
                                                     block3_shape,
                                                     block2_shape,
                                                     name="segment_side_3")
            temps.append(temp)
            segments.append(net_segment_output)  # segment

            net_output = self._decoder(block3_add,
                                       block3_shape,
                                       block2_shape,
                                       name="3")
            segments_output.append(net_output)
            pass

        with tf.variable_scope(name_or_scope="attention_2"):
            # 3  ==>
            # net_segment_block_output, temp = self._segment(block2, block2_shape, block1_shape, name="segment_side_2_block")
            # temps.append(temp)
            # segments.append(net_segment_block_output)  # segment

            # 4
            block2_add = Net.add([block2, net_output], name="add")
            adds_in_block.append(block2)
            adds_in_2.append(net_output)
            adds.append(block2_add)

            net_segment_output, temp = self._segment(block2_add,
                                                     block2_shape,
                                                     block1_shape,
                                                     name="segment_side_2")
            temps.append(temp)
            segments.append(net_segment_output)  # segment

            net_output = self._decoder(block2_add,
                                       block2_shape,
                                       block1_shape,
                                       name="2")
            segments_output.append(net_output)
            pass

        with tf.variable_scope(name_or_scope="attention_1"):
            # 5  ==>
            # net_segment_block_output, temp = self._segment(block1, block1_shape, block1_shape, name="segment_side_1_block")
            # temps.append(temp)
            # segments.append(net_segment_block_output)  # segment

            # 6
            block1_add = Net.add([block1, net_output], name="add")
            adds_in_block.append(block1)
            adds_in_2.append(net_output)
            adds.append(block1_add)

            net_segment_output, temp = self._segment(block1_add,
                                                     block1_shape,
                                                     block1_shape,
                                                     name="segment_side_1")
            temps.append(temp)
            segments.append(net_segment_output)  # segment

            net_output = self._decoder(block1_add,
                                       block1_shape,
                                       block1_shape,
                                       name="1")
            segments_output.append(net_output)
            pass

        # 7
        net_output = Net.conv(net_output,
                              3,
                              3,
                              2,
                              1,
                              1,
                              biased=True,
                              relu=False,
                              name='attention_0')
        segments.append(net_output)  # segment

        features = {
            "block": blocks,
            "segment": segments_output,
            "temp": temps,
            "add": adds,
            "adds_in_block": adds_in_block,
            "adds_in_2": adds_in_2
        }
        return segments, features