从 Mask_RCNN 张量中检索信息

我已经成功地训练了一个Mask_RCNN,为了说明目的,让我们关注网络生成的这个示例图像:

http://img4.mukewang.com/6124b24000011e1408590643.jpg

一切都很好,没问题。然而,我想要实现的是具有以下变量及其每个实例的值:


   mask:  (as an image which shows the detected object only, like a binary map)

   box: (as a list)

   mask_border_positions (x,y) : (as a list)

   mask_center_position (x,y) :  (as a tuple)

我还有将上图可视化的函数,来自官方网站:


def display_instances(image, boxes, masks, class_ids, class_names,

                      scores=None, title="",

                      figsize=(16, 16), ax=None,

                      show_mask=True, show_bbox=True,

                      colors=None, captions=None):

    """

    boxes: [num_instance, (y1, x1, y2, x2, class_id)] in image coordinates.

    masks: [height, width, num_instances]

    class_ids: [num_instances]

    class_names: list of class names of the dataset

    scores: (optional) confidence scores for each box

    title: (optional) Figure title

    show_mask, show_bbox: To show masks and bounding boxes or not

    figsize: (optional) the size of the image

    colors: (optional) An array or colors to use with each object

    captions: (optional) A list of strings to use as captions for each object

    """

    # Number of instances

    N = boxes.shape[0]

    if not N:

        print("\n*** No instances to display *** \n")

    else:

        assert boxes.shape[0] == masks.shape[-1] == class_ids.shape[0]


    # If no axis is passed, create one and automatically call show()

    auto_show = False

    if not ax:

        _, ax = plt.subplots(1, figsize=figsize)

        auto_show = True


    # Generate random colors

    colors = colors or random_colors(N)


    # Show area outside image boundaries.

    height, width = image.shape[:2]

    ax.set_ylim(height + 10, -10)

    ax.set_xlim(-10, width + 10)

    ax.axis('off')

    ax.set_title(title)


    masked_image = image.astype(np.uint32).copy()

    for i in range(N):

        color = colors[i]


偶然的你
浏览 206回答 1
1回答

皈依舞

以下是正确的:masks = p['masks']class_ids = p['class_ids']rois = p['rois']scores = p['scores']bounding_box = rois[enumerator]至于轮廓坐标:def getBoundaryPositions(im):    class_ids = p['class_ids']  # for usage convenience    im = im.astype(np.uint8)    # Find contours:    (im, contours, hierarchy) = cv2.findContours(im, cv2.RETR_EXTERNAL,            cv2.CHAIN_APPROX_NONE)    cnts = contours[0]    outline_posesXY = np.array([np.append(x[0]) for x in cnts])    # Calculate image moments of the detected contour    M = cv2.moments(contours[0])    # collect pose points (for now only position because we don't have pose) of the center    positionXY = []    positionXY.append(round(M['m10'] / M['m00']))    positionXY.append(round(M['m01'] / M['m00']))    return (im, positionXY, outline_posesXY)
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python