コード例 #1
0
def display_dataset():
    logging.basicConfig(level=logging.DEBUG)

    cfg = load_config()
    dataset = dataset_create(cfg)
    dataset.set_shuffle(False)

    while True:
        batch = dataset.next_batch()

        for frame_id in range(1):
            img = batch[Batch.inputs][frame_id, :, :, :]
            img = np.squeeze(img).astype('uint8')

            scmap = batch[Batch.part_score_targets][frame_id, :, :, :]
            scmap = np.squeeze(scmap)

            # scmask = batch[Batch.part_score_weights]
            # if scmask.size > 1:
            #     scmask = np.squeeze(scmask).astype('uint8')
            # else:
            #     scmask = np.zeros(img.shape)

            subplot_height = 4
            subplot_width = 5
            num_plots = subplot_width * subplot_height
            f, axarr = plt.subplots(subplot_height, subplot_width)

            for j in range(num_plots):
                plot_j = j // subplot_width
                plot_i = j % subplot_width

                curr_plot = axarr[plot_j, plot_i]
                curr_plot.axis('off')

                if j >= cfg.num_joints:
                    continue

                scmap_part = scmap[:, :, j]
                scmap_part = imresize(scmap_part, 8.0, interp='nearest')
                scmap_part = np.lib.pad(scmap_part, ((4, 0), (4, 0)),
                                        'minimum')

                curr_plot.set_title("{}".format(j + 1))
                curr_plot.imshow(img)
                curr_plot.hold(True)
                curr_plot.imshow(scmap_part, alpha=.5)

        # figure(0)
        # plt.imshow(np.sum(scmap, axis=2))
        # plt.figure(100)
        # plt.imshow(img)
        # plt.figure(2)
        # plt.imshow(scmask)
        plt.show()
        plt.waitforbuttonpress()
コード例 #2
0
def display_dataset():
    logging.basicConfig(level=logging.DEBUG)

    cfg = load_config()
    dataset = dataset_create(cfg)
    dataset.set_shuffle(False)

    while True:
        batch = dataset.next_batch()

        for frame_id in range(1):
            img = batch[Batch.inputs][frame_id,:,:,:]
            img = np.squeeze(img).astype('uint8')

            scmap = batch[Batch.part_score_targets][frame_id,:,:,:]
            scmap = np.squeeze(scmap)

            # scmask = batch[Batch.part_score_weights]
            # if scmask.size > 1:
            #     scmask = np.squeeze(scmask).astype('uint8')
            # else:
            #     scmask = np.zeros(img.shape)

            subplot_height = 4
            subplot_width = 5
            num_plots = subplot_width * subplot_height
            f, axarr = plt.subplots(subplot_height, subplot_width)

            for j in range(num_plots):
                plot_j = j // subplot_width
                plot_i = j % subplot_width

                curr_plot = axarr[plot_j, plot_i]
                curr_plot.axis('off')

                if j >= cfg.num_joints:
                    continue

                scmap_part = scmap[:,:,j]
                scmap_part = imresize(scmap_part, 8.0, interp='nearest')
                scmap_part = np.lib.pad(scmap_part, ((4, 0), (4, 0)), 'minimum')

                curr_plot.set_title("{}".format(j+1))
                curr_plot.imshow(img)
                curr_plot.hold(True)
                curr_plot.imshow(scmap_part, alpha=.5)

        # figure(0)
        # plt.imshow(np.sum(scmap, axis=2))
        # plt.figure(100)
        # plt.imshow(img)
        # plt.figure(2)
        # plt.imshow(scmask)
        plt.show()
        plt.waitforbuttonpress()
コード例 #3
0
ファイル: eval_pck.py プロジェクト: zoombapup/pose-tensorflow
def eval_pck(cfg):
    dataset = dataset_create(cfg)
    filename = 'predictions.mat'
    pred = sio.loadmat(filename)

    joints = pred['joints']
    pck_ratio_thresh = cfg.pck_threshold

    num_joints = cfg.num_joints
    num_images = joints.shape[1]

    pred_joints = np.zeros((num_images, num_joints, 2))
    gt_joints = np.zeros((num_images, num_joints, 2))
    pck_thresh = np.zeros((num_images, 1))
    gt_present_joints = np.zeros((num_images, num_joints))

    for k in range(num_images):
        pred = joints[0, k]
        gt = dataset.data[k].joints[0]
        if gt.shape[0] == 0:
            continue
        gt_joint_ids = gt[:, 0].astype('int32')
        rect = enclosing_rect(gt[:, 1:3])
        pck_thresh[k] = pck_ratio_thresh * np.amax(rect_size(rect))

        gt_present_joints[k, gt_joint_ids] = 1
        gt_joints[k, gt_joint_ids, :] = gt[:, 1:3]
        pred_joints[k, :, :] = pred[:, 0:2]

    dists = np.sqrt(np.sum((pred_joints - gt_joints)**2, axis=2))
    correct = dists <= pck_thresh

    num_all = np.sum(gt_present_joints, axis=0)

    num_correct = np.zeros((num_joints, ))
    for j_id in range(num_joints):
        num_correct[j_id] = np.sum(correct[gt_present_joints[:, j_id] == 1,
                                           j_id],
                                   axis=0)

    pck = num_correct / num_all * 100.0

    print_results(pck, cfg)
コード例 #4
0
def eval_pck(cfg):
    dataset = dataset_create(cfg)
    filename = 'predictions.mat'
    pred = sio.loadmat(filename)

    joints = pred['joints']
    pck_ratio_thresh = cfg.pck_threshold

    num_joints = cfg.num_joints
    num_images = joints.shape[1]

    pred_joints = np.zeros((num_images, num_joints, 2))
    gt_joints = np.zeros((num_images, num_joints, 2))
    pck_thresh = np.zeros((num_images, 1))
    gt_present_joints = np.zeros((num_images, num_joints))

    for k in range(num_images):
        pred = joints[0,k]
        gt = dataset.data[k].joints[0]
        if gt.shape[0] == 0:
            continue
        gt_joint_ids = gt[:, 0].astype('int32')
        rect = enclosing_rect(gt[:,1:3])
        pck_thresh[k] = pck_ratio_thresh*np.amax(rect_size(rect))

        gt_present_joints[k, gt_joint_ids] = 1
        gt_joints[k, gt_joint_ids, :] = gt[:,1:3]
        pred_joints[k, :, :] = pred[:,0:2]

    dists = np.sqrt(np.sum((pred_joints - gt_joints)**2, axis=2))
    correct = dists <= pck_thresh

    num_all = np.sum(gt_present_joints, axis=0)

    num_correct = np.zeros((num_joints, ))
    for j_id in range(num_joints):
        num_correct[j_id] = np.sum(correct[gt_present_joints[:,j_id] == 1, j_id], axis=0)

    pck = num_correct/num_all*100.0

    print_results(pck, cfg)
コード例 #5
0
def display_dataset():
    # 该文件可以显示训练之后的heatmap

    # 开启日志
    logging.basicConfig(level=logging.DEBUG)

    # 读取配置
    cfg = load_config()
    # 创建数据集读取类
    dataset = dataset_create(cfg)
    # 不需要对数据进行洗牌
    dataset.set_shuffle(False)

    while True:
        # 获得一批数据
        batch = dataset.next_batch()

        for frame_id in range(1):
            # 图像
            img = batch[Batch.inputs][frame_id, :, :, :]
            # 转换图像类型为uint8,8位无符号整型,范围在0-255之间
            # 正好为图像中像素值的区间范围
            img = np.squeeze(img).astype('uint8')

            # 获取heatmap
            scmap = batch[Batch.part_score_targets][frame_id, :, :, :]
            # 去掉多余的维度
            scmap = np.squeeze(scmap)

            # scmask = batch[Batch.part_score_weights]
            # if scmask.size > 1:
            #     scmask = np.squeeze(scmask).astype('uint8')
            # else:
            #     scmask = np.zeros(img.shape)

            # 画图,这里在一个窗口中画多个图所以要定义这个窗口有几行几列
            # 几行
            subplot_height = 4
            # 几列
            subplot_width = 5
            # 要画几次
            num_plots = subplot_width * subplot_height
            # 创建若干画图句柄
            f, axarr = plt.subplots(subplot_height, subplot_width)

            for j in range(num_plots):
                # 需要在第几行第几列画图
                plot_j = j // subplot_width
                plot_i = j % subplot_width

                # 获得当前的第plot_j行,第plot_i列对应的画图句柄
                curr_plot = axarr[plot_j, plot_i]
                # 将对应的坐标系的显示关闭
                curr_plot.axis('off')

                # 如果超过了需要显示的关节的个数则忽略
                if j >= cfg.num_joints:
                    continue

                # 将第j个关节的heatmap取出来
                scmap_part = scmap[:, :, j]
                # 缩放heatmap为8x8的,并且使用最近邻插值进行处理
                scmap_part = imresize(scmap_part, 8.0, interp='nearest')
                #
                scmap_part = np.lib.pad(scmap_part, ((4, 0), (4, 0)),
                                        'minimum')

                # 当前画的标题是关节的编号
                curr_plot.set_title("{}".format(j + 1))
                # 显示图片
                curr_plot.imshow(img)
                # hold(True)表示在上面显示出来的图片基础之上继续画
                curr_plot.hold(True)
                # 将关节的heatmap也画出来,设定透明度为0.5
                curr_plot.imshow(scmap_part, alpha=.5)

        # figure(0)
        # plt.imshow(np.sum(scmap, axis=2))
        # plt.figure(100)
        # plt.imshow(img)
        # plt.figure(2)
        # plt.imshow(scmask)

        # 显示窗口
        plt.show()
        # 等待按键
        plt.waitforbuttonpress()