mask rcnn input数据理解

Array.min() #无参,所有中的最小值

Array.min(0) # axis=0; 每列的最小值

Array.min(1) # axis=1;每行的最小值

 

字符串在输出时的对齐:

S.ljust(width,[fillchar])

#输出width个字符,S左对齐,不足部分用fillchar填充,默认的为空格。

S.rjust(width,[fillchar])

 #右对齐

S.center(width, [fillchar])

 #中间对齐

S.zfill(width)

#把S变成width长,并在右对齐,不足部分用0补足

def log(text, array=None):

    """Prints a text message. And, optionally, if a Numpy array is provided it

    prints it's shape, min, and max values.

    """

    if array is not None:

        text = text.ljust(25)

        text += ("shape: {:20}  ".format(str(array.shape)))

        if array.size:

            text += ("min: {:10.5f}  max: {:10.5f}".format(array.min(),array.max()))

            #{:10.5f}表示精度

        else:

            text += ("min: {:10}  max: {:10}".format("",""))

        #text += "  {}".format(array.dtype)

print(text)

从给定的mask中产生bbox

def extract_bboxes(mask):

    """Compute bounding boxes from masks.

    mask: [height, width, num_instances]. Mask pixels are either 1 or 0.

 

    Returns: bbox array [num_instances, (y1, x1, y2, x2)].

    """

    boxes = np.zeros([mask.shape[-1], 4], dtype=np.int32)

    for i in range(mask.shape[-1]):

        m = mask[:, :, i]

        # Bounding box.

        horizontal_indicies = np.where(np.any(m, axis=0))[0]

        print("np.any(m, axis=0)",np.any(m, axis=0))

        print("p.where(np.any(m, axis=0))",np.where(np.any(m, axis=0)))

        vertical_indicies = np.where(np.any(m, axis=1))[0]

        if horizontal_indicies.shape[0]:

            x1, x2 = horizontal_indicies[[0, -1]]

            y1, y2 = vertical_indicies[[0, -1]]

            # x2 and y2 should not be part of the box. Increment by 1.

            x2 += 1

            y2 += 1

        else:

            # No mask for this instance. Might happen due to

            # resizing or cropping. Set bbox to zeros

            x1, x2, y1, y2 = 0, 0, 0, 0

        boxes[i] = np.array([y1, x1, y2, x2])

    return boxes.astype(np.int32)

另外注意:

opencv默认为8位读取,如果该图为16位,则读取为全0,导致程序出错

TensorFlow的函数处理图片后存储的数据是float32格式的,需要转换成uint8才能正确打印图片

posted @ 2019-01-08 20:15  小可爱466  阅读(572)  评论(0编辑  收藏  举报