def __getitem__(self, idx):
        if self.is_trian:
            ele_anno = self.anno[self.train_list[idx]]
        else:
            ele_anno = self.anno[self.valid_list[idx]]
        res_img = [256, 256]
        res_heatmap = [64, 64]
        path_img_folder = 'mpii_human_pose_v1/images'
        path_img = os.path.join(path_img_folder, ele_anno['img_paths'])
        img_origin = imgutils.load_image(path_img)
        img_crop, ary_pts_crop, c_crop = imgutils.crop_norescale(img_origin, ele_anno)
        img_out, pts_out, c_out = imgutils.change_resolu(img_crop, ary_pts_crop, c_crop, res_heatmap)

        train_img = skimage.transform.resize(img_crop, tuple(res_img))
        train_heatmap = imgutils.generate_heatmaps(img_out, pts_out, sigma_valu=self.sigma)
        train_pts = pts_out[:, :2].astype(np.int32)

        # (H,W,C) -> (C,H,W)
        train_img = np.transpose(train_img, (2, 0, 1))
        train_heatmap = np.transpose(train_heatmap, (2, 0, 1))

        if self.use_flip:
            train_img, train_heatmap, train_pts = random_flip_LR(train_img, train_heatmap, train_pts)
        if self.use_rand_scale:
            train_img, train_heatmap, train_pts = random_scale(train_img, train_heatmap, train_pts)
        if self.use_rand_color:
            train_img = rand_color(train_img)
        return train_img, train_heatmap, train_pts
示例#2
0
num_subset = '4000(3)'  # 0 means all


j = 0
for i, idx_train in enumerate(train_list):
    if i >= idx_begin and i <= idx_end:
        j += 1
        print(anno[idx_train])
        ele_anno = anno[idx_train]
        path_img = os.path.join(path_img_folder, ele_anno['img_paths'])
        print(path_img)
        img_origin = imgutils.load_image(path_img)
        # plt.figure(1)
        # plt.imshow(img_origin)
        # plt.show()
        img_crop, ary_pts_crop, c_crop = imgutils.crop_norescale(img_origin, ele_anno, use_randscale=False)
        img_out, pts_out, c_out = imgutils.change_resolu(img_crop, ary_pts_crop, c_crop, res_heatmap)
        heatmaps = imgutils.generate_heatmaps(img_out, pts_out, sigma_valu=2)
        # plt.figure(1)
        # plt.imshow(img_out)
        # plt.show()
        train_heatmaps[j - 1, ...] = heatmaps
        # plt.figure(1)
        # plt.imshow(train_heatmaps[j-1, :, :, 0])
        # plt.show()
        # imgutils.show_stack_joints(img_out, pts_out, c_out)
        # print('heatmaps.SHAPE', train_heatmaps[j - 1, ...].shape)
        # imgutils.show_heatmaps(img_out, train_heatmaps[j - 1, ...], c_out)
        print(len_idx, '/', j)

idx_begin = 1000 * (num_subset - 1)
idx_end = idx_begin + 999
j = 0
for i, idx_train in enumerate(train_list):
    if i >= idx_begin and i <= idx_end:
        j += 1
        print(anno[idx_train])
        ele_anno = anno[idx_train]
        path_img = os.path.join(path_img_folder, ele_anno['img_paths'])
        print(path_img)
        img_origin = imgutils.load_image(path_img)
        # plt.figure(1)
        # plt.imshow(img_origin)
        # plt.show()
        img_crop, ary_pts_crop, c_crop = imgutils.crop_norescale(
            img_origin, ele_anno)
        img_out, pts_out, c_out = imgutils.change_resolu(
            img_crop, ary_pts_crop, c_crop, res_heatmap)
        # print('pts_out', pts_out)
        train_pts[j - 1, ...] = pts_out[:, :2].astype(np.int32) - np.ones(
            (16, 2))  # Cause heatmap[int(pt[1])-1][int(pt[0])-1] = 1
        # print('train_pts', train_pts[j-1, ...])

        print('1000 /', j)

# Save train_imgs
name_file = 'np__train_pts_' + str(num_subset)
np.save(name_file, train_pts)
print(
    '=====================================DONE========================================='
)