Exemplo n.º 1
0
    def draw_prediction(self, thedata, args):
        import linecache
        import re
        frame_id = np.random.randint(
            1, high=sum(1 for _ in open(self.predict_file, 'r')))
        with h5py.File(self.appen_test, 'r') as h5file:
            img_id = h5file['index'][frame_id, 0]
            # frame_h5 = np.squeeze(h5file['frame'][frame_id, ...], -1)
            # poses_h5 = h5file['poses'][frame_id, ...].reshape(-1, 3)
            resce_h5 = h5file['resce'][frame_id, ...]

        print('[{}] drawing image #{:d} ...'.format(self.name_desc, img_id))
        resce3 = resce_h5[0:4]
        cube = iso_cube()
        cube.load(resce3)
        ax = mpplot.subplot(1, 2, 1, projection='3d')
        annot_line = args.data_io.get_line(thedata.annotation_train, img_id)
        img_name, pose_raw = args.data_io.parse_line_annot(annot_line)
        img = args.data_io.read_image(os.path.join(self.image_dir, img_name))
        points3 = args.data_ops.img_to_raw(img, self.caminfo)
        numpts = points3.shape[0]
        if 1000 < numpts:
            samid = np.random.choice(numpts, 1000, replace=False)
            points3_sam = points3[samid, :]
        else:
            points3_sam = points3
        ax.scatter(points3_sam[:, 0],
                   points3_sam[:, 1],
                   points3_sam[:, 2],
                   color=Color('lightsteelblue').rgb)
        ax.view_init(azim=-90, elev=-75)
        ax.set_zlabel('depth (mm)', labelpad=15)
        args.data_draw.draw_raw3d_pose(ax, thedata, pose_raw)
        corners = cube.get_corners()
        iso_cube.draw_cube_wire(ax, corners)
        mpplot.gca().set_title('Ground truth')

        ax = mpplot.subplot(1, 2, 2, projection='3d')
        ax.scatter(points3_sam[:, 0],
                   points3_sam[:, 1],
                   points3_sam[:, 2],
                   color=Color('lightsteelblue').rgb)
        ax.view_init(azim=-90, elev=-75)
        ax.set_zlabel('depth (mm)', labelpad=15)
        args.data_draw.draw_raw3d_pose(ax, thedata, pose_raw)

        line_pred = linecache.getline(self.predict_file, frame_id)
        pred_list = re.split(r'\s+', line_pred.strip())
        centre = np.array([float(i) for i in pred_list[1:4]])
        cube = iso_cube(centre, self.region_size)
        # cube.show_dims()
        corners = cube.get_corners()
        iso_cube.draw_cube_wire(ax, corners)
        mpplot.gca().set_title('Prediction')

        print('[{}] drawing image #{:d} - done.'.format(
            self.name_desc, img_id))
Exemplo n.º 2
0
    def draw_random(self, thedata, args):
        import matplotlib.pyplot as mpplot
        from mpl_toolkits.mplot3d import Axes3D
        from mayavi import mlab

        # mlab.figure(size=(800, 800))
        # # cube = iso_cube()
        # # points3_trans = np.hstack(
        # #     (np.zeros((10, 2)), np.arange(-1, 1, 0.2).reshape(10, 1)))
        # # grid = regu_grid()
        # # grid.from_cube(cube, 6)
        # # pcnt = grid.fill(points3_trans)
        #
        # pcnt = np.zeros((6, 6, 6))
        # pcnt[2:4, 2:4, 3] = 1
        # frame = args.data_ops.prop_dist(pcnt)
        # mlab.pipeline.volume(mlab.pipeline.scalar_field(frame))
        # mlab.pipeline.image_plane_widget(
        #     mlab.pipeline.scalar_field(frame),
        #     plane_orientation='z_axes',
        #     slice_index=self.crop_size / 2)
        # print(pcnt[..., 3])
        # print(frame[..., 3])
        # print(frame[0, 0, 3], type(frame[0, 0, 3]))
        # mlab.outline()
        # mlab.show()
        # os._exit(0)

        # mode = 'train'
        mode = 'test'
        store_handle = self.store_handle[mode]
        index_h5 = store_handle['index']
        store_size = index_h5.shape[0]
        frame_id = np.random.choice(store_size)
        # frame_id = 0  # frame_id = img_id - 1
        # frame_id = 239
        img_id = index_h5[frame_id, ...]
        frame_h5 = store_handle['pcnt3'][frame_id, ...]
        poses_h5 = store_handle['pose_c'][frame_id, ...].reshape(-1, 3)
        resce_h5 = store_handle['resce'][frame_id, ...]

        print('[{}] drawing image #{:d} ...'.format(self.name_desc, img_id))
        print(np.min(frame_h5), np.max(frame_h5))
        print(np.histogram(frame_h5, range=(1e-4, np.max(frame_h5))))
        from colour import Color
        colors = [Color('orange').rgb, Color('red').rgb, Color('lime').rgb]
        resce3 = resce_h5[0:4]
        cube = iso_cube()
        cube.load(resce3)
        fig, _ = mpplot.subplots(nrows=2, ncols=2, figsize=(2 * 5, 2 * 5))

        ax = mpplot.subplot(2, 2, 1)
        img_name = args.data_io.index2imagename(img_id)
        img = args.data_io.read_image(
            self.data_inst.images_join(img_name, mode))
        ax.imshow(img, cmap=mpplot.cm.bone_r)
        pose_raw = self.yanker(poses_h5, resce_h5, self.caminfo)
        args.data_draw.draw_pose2d(
            ax, thedata, args.data_ops.raw_to_2d(pose_raw, self.caminfo))
        rects = cube.proj_rects_3(args.data_ops.raw_to_2d, self.caminfo)
        for ii, rect in enumerate(rects):
            rect.draw(ax, colors[ii])

        ax = mpplot.subplot(2, 2, 3, projection='3d')
        resce3 = resce_h5[0:4]
        cube = iso_cube()
        cube.load(resce3)
        cube.show_dims()
        points3 = args.data_ops.img_to_raw(img, self.caminfo)
        points3_trans = cube.pick(points3)
        points3_trans = cube.transform_to_center(points3_trans)
        numpts = points3_trans.shape[0]
        if 1000 < numpts:
            points3_trans = points3_trans[
                np.random.choice(numpts, 1000, replace=False), :]
        ax.scatter(points3_trans[:, 0],
                   points3_trans[:, 1],
                   points3_trans[:, 2],
                   color=Color('lightsteelblue').rgb)
        pose_c = cube.transform_to_center(pose_raw)
        args.data_draw.draw_raw3d_pose(ax, thedata, pose_c)
        corners = cube.transform_to_center(cube.get_corners())
        cube.draw_cube_wire(ax, corners)
        ax.view_init(azim=-120, elev=-150)

        ax = mpplot.subplot(2, 2, 2, projection='3d')
        numpts = points3.shape[0]
        if 1000 < numpts:
            samid = np.random.choice(numpts, 1000, replace=False)
            points3_sam = points3[samid, :]
        else:
            points3_sam = points3
        ax.scatter(points3_sam[:, 0],
                   points3_sam[:, 1],
                   points3_sam[:, 2],
                   color=Color('lightsteelblue').rgb)
        ax.view_init(azim=-90, elev=-75)
        ax.set_zlabel('depth (mm)', labelpad=15)
        args.data_draw.draw_raw3d_pose(ax, thedata, pose_raw)
        corners = cube.get_corners()
        iso_cube.draw_cube_wire(ax, corners)

        voxize_crop = self.crop_size
        grid = regu_grid()
        grid.from_cube(cube, voxize_crop)
        vxcnt_crop = frame_h5

        def draw_voxel_pose(ax, poses, roll=0):
            pose3d = cube.transform_center_shrink(poses)
            pose2d, _ = cube.project_ortho(pose3d, roll=roll, sort=False)
            pose2d *= voxize_crop
            args.data_draw.draw_pose2d(
                ax,
                thedata,
                pose2d,
            )
            coord = grid.slice_ortho(vxcnt_crop, roll=roll)
            grid.draw_slice(ax, coord, 1.)
            ax.set_xlim([0, voxize_crop])
            ax.set_ylim([0, voxize_crop])
            ax.set_aspect('equal', adjustable='box')
            ax.invert_yaxis()

        ax = mpplot.subplot(2, 2, 4)
        draw_voxel_pose(ax, pose_raw, roll=0)

        # if not self.args.show_draw:
        #     mlab.options.offscreen = True
        #     mlab.figure(size=(800, 800))
        #     points3_trans = cube.transform_to_center(points3_sam)
        #     mlab.points3d(
        #         points3_trans[:, 0], points3_trans[:, 1], points3_trans[:, 2],
        #         scale_factor=8,
        #         color=Color('lightsteelblue').rgb)
        #     mlab.outline()

        if not self.args.show_draw:
            mlab.options.offscreen = True
        else:
            mlab.figure(size=(800, 800))
            # mlab.contour3d(frame)
            mlab.pipeline.volume(mlab.pipeline.scalar_field(frame_h5))
            mlab.pipeline.image_plane_widget(
                mlab.pipeline.scalar_field(frame_h5),
                plane_orientation='z_axes',
                slice_index=self.crop_size / 2)
            np.set_printoptions(precision=4)
            # print(frame[12:20, 12:20, 16])
            mlab.outline()
            from utils.image_ops import draw_dist3
            draw_dist3(vxcnt_crop, voxize_crop, 2)
            mlab.draw()
            mlab.savefig(
                os.path.join(self.predict_dir,
                             'draw3d_{}_{}.png'.format(self.name_desc,
                                                       img_id)))

        fig.tight_layout()
        mpplot.savefig(
            os.path.join(self.predict_dir,
                         'draw_{}_{}.png'.format(self.name_desc, img_id)))
        if self.args.show_draw:
            mpplot.show()
            mlab.close(all=True)
        print('[{}] drawing image #{:d} - done.'.format(
            self.name_desc, img_id))
Exemplo n.º 3
0
    def draw_random(self, thedata, args):
        from mayavi import mlab
        with h5py.File(self.appen_train, 'r') as h5file:
            store_size = h5file['index'].shape[0]
            frame_id = np.random.choice(store_size)
            img_id = h5file['index'][frame_id, 0]
            frame_h5 = np.squeeze(h5file['frame'][frame_id, ...], axis=-1)
            poses_h5 = h5file['poses'][frame_id, ...]
            resce_h5 = h5file['resce'][frame_id, ...]

        print('[{}] drawing image #{:d} ...'.format(self.name_desc, img_id))
        # colors = [Color('orange').rgb, Color('red').rgb, Color('lime').rgb]
        fig, _ = mpplot.subplots(nrows=2, ncols=2, figsize=(2 * 5, 2 * 5))
        ax = mpplot.subplot(2, 2, 1)
        mpplot.gca().set_title('test input')
        annot_line = args.data_io.get_line(thedata.annotation_train, img_id)
        img_name, pose_raw = args.data_io.parse_line_annot(annot_line)
        img = args.data_io.read_image(os.path.join(self.image_dir, img_name))
        ax.imshow(img, cmap=mpplot.cm.bone_r)
        args.data_draw.draw_pose2d(
            ax, thedata, args.data_ops.raw_to_2d(pose_raw, self.caminfo))

        ax = mpplot.subplot(2, 2, 3, projection='3d')
        mpplot.gca().set_title('test storage read')
        resce3 = resce_h5[0:4]
        cube = iso_cube()
        cube.load(resce3)
        cube.show_dims()
        points3 = args.data_ops.img_to_raw(img, self.caminfo)
        numpts = points3.shape[0]
        if 1000 < numpts:
            points3_sam = points3[
                np.random.choice(numpts, 1000, replace=False), :]
        else:
            points3_sam = points3
        ax.scatter(points3_sam[:, 0],
                   points3_sam[:, 1],
                   points3_sam[:, 2],
                   color=Color('lightsteelblue').rgb)
        ax.view_init(azim=-90, elev=-75)
        ax.set_zlabel('depth (mm)', labelpad=15)
        args.data_draw.draw_raw3d_pose(ax, thedata, pose_raw)
        corners = cube.get_corners()
        iso_cube.draw_cube_wire(ax, corners)

        ax = mpplot.subplot(2, 2, 4)
        mpplot.gca().set_title('test output')
        img_name = args.data_io.index2imagename(img_id)
        img = args.data_io.read_image(os.path.join(self.image_dir, img_name))
        ax.imshow(img, cmap=mpplot.cm.bone_r)

        ax = mpplot.subplot(2, 2, 2, projection='3d')
        mpplot.gca().set_title('test storage write')
        numpts = points3.shape[0]
        if 1000 < numpts:
            samid = np.random.choice(numpts, 1000, replace=False)
            points3_sam = points3[samid, :]
        else:
            points3_sam = points3
        ax.scatter(points3_sam[:, 0],
                   points3_sam[:, 1],
                   points3_sam[:, 2],
                   color=Color('lightsteelblue').rgb)
        ax.view_init(azim=-90, elev=-75)
        ax.set_zlabel('depth (mm)', labelpad=15)
        args.data_draw.draw_raw3d_pose(ax, thedata, pose_raw)
        corners = cube.get_corners()
        iso_cube.draw_cube_wire(ax, corners)

        mlab.figure(size=(800, 800))
        img_name, frame, poses, resce = self.provider_worker(
            annot_line, self.image_dir, self.caminfo)
        frame = np.squeeze(frame, axis=-1)
        if ((1e-4 < np.linalg.norm(frame_h5 - frame))
                or (1e-4 < np.linalg.norm(poses_h5 - poses))):
            print(np.linalg.norm(frame_h5 - frame))
            print(np.linalg.norm(poses_h5 - poses))
            _, frame_1, _, _ = self.provider_worker(annot_line, self.image_dir,
                                                    self.caminfo)
            print(np.linalg.norm(frame_1 - frame))
            with h5py.File('/tmp/111', 'w') as h5file:
                h5file.create_dataset('frame', data=frame_1, dtype='f4')
            with h5py.File('/tmp/111', 'r') as h5file:
                frame_2 = h5file['frame'][:]
                print(np.linalg.norm(frame_1 - frame_2))
            print('ERROR - h5 storage corrupted!')
        resce3 = resce_h5[0:4]
        cube = iso_cube()
        cube.load(resce3)
        cube.show_dims()
        # mlab.contour3d(frame)
        mlab.pipeline.volume(mlab.pipeline.scalar_field(frame))
        mlab.pipeline.image_plane_widget(mlab.pipeline.scalar_field(frame),
                                         plane_orientation='z_axes',
                                         slice_index=self.crop_size / 2)
        np.set_printoptions(precision=4)
        # print(frame[12:20, 12:20, 16])
        mlab.outline()

        fig.tight_layout()
        mpplot.savefig(
            os.path.join(self.predict_dir,
                         'draw_{}_{}.png'.format(self.name_desc, img_id)))
        if self.args.show_draw:
            mpplot.show()
        print('[{}] drawing image #{:d} - done.'.format(
            self.name_desc, img_id))
Exemplo n.º 4
0
    def draw_random(self, thedata, args):
        import matplotlib.pyplot as mpplot
        from mpl_toolkits.mplot3d import Axes3D
        from mayavi import mlab

        # mode = 'train'
        mode = 'test'
        store_handle = self.store_handle[mode]
        index_h5 = store_handle['index']
        store_size = index_h5.shape[0]
        frame_id = np.random.choice(store_size)
        # frame_id = 0  # frame_id = img_id - 1
        # frame_id = 239
        img_id = index_h5[frame_id, ...]
        frame_h5 = store_handle['vxhit'][frame_id, ...]
        poses_h5 = store_handle['poses'][frame_id, ...].reshape(-1, 3)
        pose_lab_h5 = store_handle['pose_lab'][frame_id, ...]
        resce_h5 = store_handle['resce'][frame_id, ...]

        print('[{}] drawing image #{:d} ...'.format(self.name_desc, img_id))
        print(np.min(frame_h5), np.max(frame_h5))
        print(np.histogram(frame_h5, range=(1e-4, np.max(frame_h5))))
        print(resce_h5)
        resce3 = resce_h5[0:4]
        cube = iso_cube()
        cube.load(resce3)
        cube.show_dims()
        img_name = args.data_io.index2imagename(img_id)
        img = args.data_io.read_image(
            self.data_inst.images_join(img_name, mode))
        from colour import Color
        colors = [Color('orange').rgb, Color('red').rgb, Color('lime').rgb]
        fig, _ = mpplot.subplots(nrows=2, ncols=4, figsize=(4 * 5, 2 * 5))
        voxize_crop = self.crop_size
        voxize_hmap = self.hmap_size
        scale = self.map_scale

        ax = mpplot.subplot(2, 4, 3, projection='3d')
        points3 = args.data_ops.img_to_raw(img, self.caminfo)
        points3_trans = cube.pick(points3)
        # points3_trans = cube.transform_to_center(points3_trans)
        numpts = points3_trans.shape[0]
        if 1000 < numpts:
            points3_trans = points3_trans[
                np.random.choice(numpts, 1000, replace=False), :]
        ax.scatter(points3_trans[:, 0],
                   points3_trans[:, 1],
                   points3_trans[:, 2],
                   color=Color('lightsteelblue').rgb)
        args.data_draw.draw_raw3d_pose(ax, thedata, poses_h5)
        corners = cube.get_corners()
        # corners = cube.transform_to_center(corners)
        cube.draw_cube_wire(ax, corners)
        ax.view_init(azim=-90, elev=-75)

        ax = mpplot.subplot(2, 4, 1)
        ax.imshow(img, cmap=mpplot.cm.bone_r)
        pose_raw = poses_h5
        args.data_draw.draw_pose2d(
            ax, thedata, args.data_ops.raw_to_2d(pose_raw, self.caminfo))
        rects = cube.proj_rects_3(args.data_ops.raw_to_2d, self.caminfo)
        for ii, rect in enumerate(rects):
            rect.draw(ax, colors[ii])

        ax = mpplot.subplot(2, 4, 2, projection='3d')
        numpts = points3.shape[0]
        if 1000 < numpts:
            samid = np.random.choice(numpts, 1000, replace=False)
            points3_sam = points3[samid, :]
        else:
            points3_sam = points3
        ax.scatter(points3_sam[:, 0],
                   points3_sam[:, 1],
                   points3_sam[:, 2],
                   color=Color('lightsteelblue').rgb)
        ax.view_init(azim=-90, elev=-75)
        ax.set_zlabel('depth (mm)', labelpad=15)
        args.data_draw.draw_raw3d_pose(ax, thedata, pose_raw)
        corners = cube.get_corners()
        iso_cube.draw_cube_wire(ax, corners)

        ax = mpplot.subplot(2, 4, 4, projection='3d')
        # grid = regu_grid()
        # grid.from_cube(cube, self.crop_size)
        # grid.draw_map(ax, frame_h5)
        args.data_draw.draw_raw3d_pose(ax, thedata, pose_raw)
        # from cv2 import resize as cv2resize
        # import cv2
        # img_hmap = cv2resize(img, (241, 241))
        # img_hmap = (img_hmap / np.max(img_hmap)) * 255
        # # fig2d, _ = mpplot.subplots()
        # # ax2d = mpplot.subplot(1, 1, 1)
        # # ax2d.imshow(img)
        # # img_hmap = fig2data(fig2d)
        # # img_hmap = (255. * img_hmap / np.max(img_hmap)).astype(int)
        # # img_hmap = img_hmap / np.max(img_hmap)
        # img_hmap = cv2.cvtColor(img_hmap, cv2.COLOR_GRAY2RGB)
        # # x, y = np.ogrid[0:cube.sidelen, 0:cube.sidelen]
        # x, y = np.mgrid[-cube.sidelen:cube.sidelen, -cube.sidelen:cube.sidelen]
        # ax.plot_surface(
        #     # x, y, cube.sidelen,
        #     x, y,
        #     np.ones_like(x) * cube.sidelen,
        #     rstride=2, cstride=2,
        #     facecolors=img_hmap)
        ax.view_init(azim=-90, elev=-75)
        # axlim = cube.sidelen * 0.8
        # ax.set_xlim([-axlim, axlim])
        # ax.set_ylim([-axlim, axlim])
        # ax.set_zlim([-axlim, axlim])
        # ax.set_aspect('equal', adjustable='box')
        ax.set_zlabel('depth (mm)', labelpad=15)

        pose_yank = self.yanker_hmap(pose_lab_h5, resce3, self.caminfo)
        diff = np.abs(pose_raw - pose_yank)
        print(diff)
        print(np.min(diff, axis=0), np.max(diff, axis=0))
        grid = regu_grid()
        grid.from_cube(cube, voxize_crop)
        vxcnt_crop = frame_h5

        def draw_voxel_pose(ax, poses, roll=0):
            pose3d = cube.transform_center_shrink(poses)
            pose2d, _ = cube.project_ortho(pose3d, roll=roll, sort=False)
            pose2d *= voxize_crop
            args.data_draw.draw_pose2d(
                ax,
                thedata,
                pose2d,
            )
            coord = grid.slice_ortho(vxcnt_crop, roll=roll)
            grid.draw_slice(ax, coord, 1.)
            ax.set_xlim([0, voxize_crop])
            ax.set_ylim([0, voxize_crop])
            ax.set_aspect('equal', adjustable='box')
            ax.invert_yaxis()

        ax = mpplot.subplot(2, 4, 5)
        draw_voxel_pose(ax, pose_raw, roll=0)

        roll = 1
        ax = mpplot.subplot(2, 4, 6)
        draw_voxel_pose(ax, pose_yank, roll=roll)

        from utils.image_ops import draw_vxlab
        ax = mpplot.subplot(2, 4, 7)
        draw_vxlab(fig, ax, vxcnt_crop, pose_lab_h5, voxize_hmap, roll=0)

        ax = mpplot.subplot(2, 4, 8)
        draw_vxlab(fig, ax, vxcnt_crop, pose_lab_h5, voxize_hmap, roll=roll)

        # if not self.args.show_draw:
        #     mlab.options.offscreen = True
        # else:
        #     mlab.figure(size=(800, 800))
        #     # mlab.contour3d(frame_h5)
        #     mlab.pipeline.volume(mlab.pipeline.scalar_field(frame_h5))
        #     mlab.pipeline.image_plane_widget(
        #         mlab.pipeline.scalar_field(frame_h5),
        #         plane_orientation='z_axes',
        #         slice_index=self.crop_size / 2)
        #     np.set_printoptions(precision=4)
        #     # print(frame_h5[12:20, 12:20, 16])
        #     mlab.outline()

        # if not self.args.show_draw:
        #     mlab.options.offscreen = True
        # else:
        #     from utils.image_ops import draw_dist3
        #     vxmap = np.zeros(voxize_hmap * voxize_hmap * voxize_hmap)
        #     vxmap[pose_lab_h5[-1].astype(int)] = 1
        #     vxmap = vxmap.reshape((voxize_hmap, voxize_hmap, voxize_hmap))
        #     draw_dist3(vxmap, voxize_crop, scale)
        #     mlab.draw()
        #     mlab.savefig(os.path.join(
        #         self.predict_dir,
        #         'draw3d_{}_{}.png'.format(self.name_desc, img_id)))
        #
        fig.tight_layout()
        mpplot.savefig(
            os.path.join(self.predict_dir,
                         'draw_{}_{}.png'.format(self.name_desc, img_id)))
        if self.args.show_draw:
            mpplot.show()
            # mlab.close(all=True)
        print('[{}] drawing image #{:d} - done.'.format(
            self.name_desc, img_id))
Exemplo n.º 5
0
    def draw_random(self, thedata, args):
        with h5py.File(self.appen_train, 'r') as h5file:
            store_size = h5file['index'].shape[0]
            frame_id = np.random.choice(store_size)
            img_id = h5file['index'][frame_id, 0]
            frame_h5 = np.squeeze(h5file['frame'][frame_id, ...], -1)
            poses_h5 = h5file['poses'][frame_id, ...]
            resce_h5 = h5file['resce'][frame_id, ...]
            frame_h5 = args.data_ops.frame_size_localizer(
                frame_h5, self.caminfo)

        print('[{}] drawing image #{:d} ...'.format(self.name_desc, img_id))
        colors = [Color('orange').rgb, Color('red').rgb, Color('lime').rgb]
        fig, _ = mpplot.subplots(nrows=2, ncols=2, figsize=(2 * 5, 2 * 5))
        ax = mpplot.subplot(2, 2, 1)
        mpplot.gca().set_title('test input')
        annot_line = args.data_io.get_line(thedata.annotation_train, img_id)
        img_name, pose_raw = args.data_io.parse_line_annot(annot_line)
        img = args.data_io.read_image(os.path.join(self.image_dir, img_name))
        ax.imshow(img, cmap=mpplot.cm.bone_r)
        args.data_draw.draw_pose2d(ax, thedata,
                                   args.data_ops.raw_to_2d(pose_raw, thedata))

        ax = mpplot.subplot(2, 2, 3, projection='3d')
        mpplot.gca().set_title('test storage read')
        resce3 = resce_h5[0:4]
        cube = iso_cube()
        cube.load(resce3)
        cube.show_dims()
        points3 = args.data_ops.img_to_raw(frame_h5, thedata)
        numpts = points3.shape[0]
        if 1000 < numpts:
            points3_sam = points3[
                np.random.choice(numpts, 1000, replace=False), :]
        else:
            points3_sam = points3
        ax.scatter(points3_sam[:, 0],
                   points3_sam[:, 1],
                   points3_sam[:, 2],
                   color=Color('lightsteelblue').rgb)
        ax.view_init(azim=-90, elev=-75)
        ax.set_zlabel('depth (mm)', labelpad=15)
        args.data_draw.draw_raw3d_pose(ax, thedata, pose_raw)
        corners = cube.get_corners()
        iso_cube.draw_cube_wire(ax, corners)

        ax = mpplot.subplot(2, 2, 4)
        mpplot.gca().set_title('test output')
        img_name = args.data_io.index2imagename(img_id)
        img = args.data_io.read_image(os.path.join(self.image_dir, img_name))
        ax.imshow(img, cmap=mpplot.cm.bone_r)
        anchor_num = self.anchor_num**2
        pcnt = poses_h5[:anchor_num].reshape(
            (self.anchor_num, self.anchor_num))
        print(pcnt)
        index = np.array(np.unravel_index(np.argmax(pcnt), pcnt.shape))
        anchors = poses_h5[anchor_num:]
        print(index)
        points2, wsizes, centre = self.yank_rect(index, anchors, self.caminfo)
        print(np.append(points2, wsizes).reshape(1, -1))
        rect = iso_rect(points2 - wsizes, wsizes * 2)
        rect.draw(ax)
        cube = iso_cube(centre.flatten(), self.region_size)
        cube.show_dims()
        rects = cube.proj_rects_3(args.data_ops.raw_to_2d, self.caminfo)
        for ii, rect in enumerate(rects):
            rect.draw(ax, colors[ii])

        ax = mpplot.subplot(2, 2, 2)
        mpplot.gca().set_title('test storage write')
        img_name, frame, poses, resce = self.provider_worker(
            annot_line, self.image_dir, thedata)
        frame = args.data_ops.frame_size_localizer(frame, self.caminfo)
        if ((1e-4 < np.linalg.norm(frame_h5 - frame))
                or (1e-4 < np.linalg.norm(poses_h5 - poses))):
            print(np.linalg.norm(frame_h5 - frame))
            print(np.linalg.norm(poses_h5 - poses))
            print('ERROR - h5 storage corrupted!')
        ax.imshow(frame, cmap=mpplot.cm.bone_r)
        resce3 = resce[0:4]
        cube = iso_cube()
        cube.load(resce3)
        cube.show_dims()
        rects = cube.proj_rects_3(args.data_ops.raw_to_2d, self.caminfo)
        for ii, rect in enumerate(rects):
            rect.draw(ax, colors[ii])

        fig.tight_layout()
        mpplot.savefig(
            os.path.join(self.predict_dir,
                         'draw_{}_{}.png'.format(self.name_desc, img_id)))
        if self.args.show_draw:
            mpplot.show()
        print('[{}] drawing image #{:d} - done.'.format(
            self.name_desc, img_id))