(self, conv_output, anchors, stride)
return tf.concat([pred_xywh, pred_conf, pred_prob], axis=-1)
return tensor of shape [batch_size, output_size, output_size, anchor_per_scale, 5 + num_classes]
               contains (x, y, w, h, score, probability)
return tensor of shape [batch_size, output_size, output_size, anchor_per_scale, 5 + num_classes]
               contains (x, y, w, h, score, probability)
return tensor of shape [ batch_size output_size output_size anchor_per_scale 5 + num_classes ] contains ( x y w h score probability )
def decode(self, conv_output, anchors, stride):
        """
        return tensor of shape [batch_size, output_size, output_size, anchor_per_scale, 5 + num_classes]
               contains (x, y, w, h, score, probability)
        """

        conv_shape       = tf.shape(conv_output)
        batch_size       = conv_shape[0]
        output_size      = conv_shape[1]
        anchor_per_scale = len(anchors)

        conv_output = tf.reshape(conv_output, (batch_size, output_size, output_size, anchor_per_scale, 5 + self.num_class))

        conv_raw_dxdy = conv_output[:, :, :, :, 0:2]
        conv_raw_dwdh = conv_output[:, :, :, :, 2:4]
        conv_raw_conf = conv_output[:, :, :, :, 4:5]
        conv_raw_prob = conv_output[:, :, :, :, 5: ]

        y = tf.tile(tf.range(output_size, dtype=tf.int32)[:, tf.newaxis], [1, output_size])
        x = tf.tile(tf.range(output_size, dtype=tf.int32)[tf.newaxis, :], [output_size, 1])

        xy_grid = tf.concat([x[:, :, tf.newaxis], y[:, :, tf.newaxis]], axis=-1)
        xy_grid = tf.tile(xy_grid[tf.newaxis, :, :, tf.newaxis, :], [batch_size, 1, 1, anchor_per_scale, 1])
        xy_grid = tf.cast(xy_grid, tf.float32)

        pred_xy = (tf.sigmoid(conv_raw_dxdy) + xy_grid) * stride
        pred_wh = (tf.exp(conv_raw_dwdh) * anchors) * stride
        pred_xywh = tf.concat([pred_xy, pred_wh], axis=-1)

        pred_conf = tf.sigmoid(conv_raw_conf)
        pred_prob = tf.sigmoid(conv_raw_prob)

        return tf.concat([pred_xywh, pred_conf, pred_prob], axis=-1)
def decode ( self , conv_output , anchors , stride ) : conv_shape = tf . shape ( conv_output ) batch_size = conv_shape [ 0 ] output_size = conv_shape [ 1 ] anchor_per_scale = len ( anchors ) conv_output = tf . reshape ( conv_output , ( batch_size , output_size , output_size , anchor_per_scale , 5 + self . num_class ) ) conv_raw_dxdy = conv_output [ : , : , : , : , 0 : 2 ] conv_raw_dwdh = conv_output [ : , : , : , : , 2 : 4 ] conv_raw_conf = conv_output [ : , : , : , : , 4 : 5 ] conv_raw_prob = conv_output [ : , : , : , : , 5 : ] y = tf . tile ( tf . range ( output_size , dtype = tf . int32 ) [ : , tf . newaxis ] , [ 1 , output_size ] ) x = tf . tile ( tf . range ( output_size , dtype = tf . int32 ) [ tf . newaxis , : ] , [ output_size , 1 ] ) xy_grid = tf . concat ( [ x [ : , : , tf . newaxis ] , y [ : , : , tf . newaxis ] ] , axis = - 1 ) xy_grid = tf . tile ( xy_grid [ tf . newaxis , : , : , tf . newaxis , : ] , [ batch_size , 1 , 1 , anchor_per_scale , 1 ] ) xy_grid = tf . cast ( xy_grid , tf . float32 ) pred_xy = ( tf . sigmoid ( conv_raw_dxdy ) + xy_grid ) * stride pred_wh = ( tf . exp ( conv_raw_dwdh ) * anchors ) * stride pred_xywh = tf . concat ( [ pred_xy , pred_wh ] , axis = - 1 ) pred_conf = tf . sigmoid ( conv_raw_conf ) pred_prob = tf . sigmoid ( conv_raw_prob ) return tf . concat ( [ pred_xywh , pred_conf , pred_prob ] , axis = - 1 )