为了账号安全,请及时绑定邮箱和手机立即绑定

从 Mask_RCNN 张量中检索信息

从 Mask_RCNN 张量中检索信息

偶然的你 2021-08-24 16:47:06
我已经成功地训练了一个Mask_RCNN,为了说明目的,让我们关注网络生成的这个示例图像:一切都很好,没问题。然而,我想要实现的是具有以下变量及其每个实例的值:   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]
查看完整描述

1 回答

?
皈依舞

TA贡献1851条经验 获得超3个赞

以下是正确的:


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)


查看完整回答
反对 回复 2021-08-24
  • 1 回答
  • 0 关注
  • 205 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信