def get_example(self, i):
        pc = load_pointcloud_from_bin(self.velo_list[i])
        calib = read_calib_file(self.calib_list[i])
        proj_velo = proj_img_to_velo(calib)  # R0_rect / Tr_velo_to_cam
        self.rect_cam = calib["P2"].reshape(3, 4)[:, :3]
        self.proj_cam = np.linalg.inv(proj_velo)

        random_indexes = np.random.permutation(pc.shape[0])
        pc = pc[random_indexes]

        d, h, w = self.voxel_shape
        d_res, h_res, w_res = self.resolution
        x_min, x_max = self.x_range
        y_min, y_max = self.y_range
        z_min, z_max = self.z_range
        rotate = 0

        pc = np.ascontiguousarray(pc, dtype=np.float32)
        create_input = create_feature_input_rotate if self.norm_input else create_feature_input
        s = time.time()
        feature_input, counter, indexes, n_no_empty = \
            create_input(pc, d_res, h_res, w_res, self.t,
                         d, h, w, x_min, x_max, y_min, y_max, z_min, z_max,
                         self.thres_t, 0, 92)
        print("create input", time.time() - s)

        area_mask = create_mask(0, 90, d, h, w,
                                self.scale_label).astype(np.int8)

        return (feature_input, counter, indexes, np.array([indexes.shape[0]]),
                np.array([n_no_empty]), area_mask)
示例#2
0
def _transform(inputs,
               crop_size=(512, 512),
               g_scale=[0.95, 1.05],
               l_rotate=None,
               g_rotate=None,
               resolution=None,
               voxel_shape=None,
               x_range=None,
               y_range=None,
               z_range=None,
               t=35,
               thres_t=None,
               anchor_size=(1.56, 1.6, 3.9),
               anchor_center=(-1.0, 0., 0.),
               fliplr=False,
               n_class=20,
               scale_label=1,
               norm_input=False):
    pc, places, rotates, size = inputs

    d, h, w = voxel_shape
    d_res, h_res, w_res = resolution
    x_min, x_max = x_range
    y_min, y_max = y_range
    z_min, z_max = z_range

    places[:, 2] += size[:, 0] / 2.

    s = time.time()
    create_input = create_feature_input_rotate if norm_input else create_feature_input
    feature_input, counter, indexes, n_no_empty = \
        create_input(pc, d_res, h_res, w_res, t, d, h, w,
                     x_min, x_max, y_min, y_max, z_min, z_max, thres_t, 0, 92)
    print("Convert raw data to input", time.time() - s)
    del pc

    anchor_z, anchor_y, anchor_x = anchor_center
    anchor_h, anchor_w, anchor_l = anchor_size
    area_mask = create_mask(0, 90, d, h, w, scale_label)

    # label_creator = create_label_rotate if label_rotate else create_label
    gt_obj, gt_reg, _ = create_label_rotate(places, rotates, size, d_res,
                                            h_res, w_res, t, d, h, w, x_min,
                                            x_max, y_min, y_max, z_min, z_max,
                                            thres_t, anchor_l, anchor_w,
                                            anchor_h, anchor_x, anchor_y,
                                            anchor_z, scale_label, 0.8)

    return (feature_input, counter, indexes, gt_obj, gt_reg, area_mask[None],
            np.array([indexes.shape[0]]), np.array([n_no_empty]))
def _transform(inputs,
               crop_size=(512, 512),
               g_scale=[0.95, 1.05],
               l_rotate=None,
               g_rotate=None,
               resolution=None,
               voxel_shape=None,
               x_range=None,
               y_range=None,
               z_range=None,
               t=35,
               thres_t=None,
               anchor_size=(1.56, 1.6, 3.9),
               anchor_center=(-1.0, 0., 0.),
               fliplr=False,
               n_class=20,
               scale_label=1,
               norm_input=False,
               label_rotate=False,
               angle=90,
               surround_prob=1):
    pc, places, rotates, size = inputs
    del inputs

    places[:, 2] += size[:, 0] / 2.

    rotates = np.pi / 2 - rotates
    rotates = aug_rotate(rotates, 0)

    # Local rotation (Label and local points) # TODO
    if l_rotate:
        l_rotate = np.random.uniform(l_rotate[0], l_rotate[1])

    # Global scaling
    if g_scale:
        scale = np.random.uniform(g_scale[0], g_scale[1], 4)
        pc *= scale
        places *= scale[:3]
        size *= scale[:3]

    # Global rotation
    r = 0
    if g_rotate:
        g_rotate = np.random.uniform(g_rotate[0], g_rotate[1])
        r = float(g_rotate / 180 * np.pi)
        rotate_matrix = np.array([[np.cos(r), -np.sin(r), 0],
                                  [np.sin(r), np.cos(r), 0], [0, 0, 1]])
        pc[:, :3] = np.dot(pc[:, :3], rotate_matrix.transpose())
        places = np.dot(places, rotate_matrix.transpose()).astype("f")
        rotates = aug_rotate(rotates, r)

    # Flip
    if fliplr:
        if np.random.rand() > 0.5:
            pc[:, 1] = pc[:, 1] * -1
            places[:, 1] = places[:, 1] * -1
            rotates = rotates * -1
            r = r * -1

    random_indexes = np.random.permutation(pc.shape[0])
    pc = pc[random_indexes]

    d, h, w = voxel_shape
    d_res, h_res, w_res = resolution
    x_min, x_max = x_range
    y_min, y_max = y_range
    z_min, z_max = z_range

    area_mask = create_mask(r, angle, d, h, w, scale_label)

    create_input = create_feature_input_rotate if norm_input else create_feature_input
    pc = np.ascontiguousarray(pc, dtype=np.float32)

    feature_input, counter, indexes, n_no_empty = \
        create_input(pc, d_res, h_res, w_res, t, d, h, w,
                     x_min, x_max, y_min, y_max, z_min, z_max, thres_t, r, angle)
    del pc

    anchor_z, anchor_y, anchor_x = anchor_center
    anchor_h, anchor_w, anchor_l = anchor_size

    # bird_corners = get_bird_boxcorners(places, rotates, size)

    label_creator = create_label_rotate  #if label_rotate else create_label
    gt_obj, gt_reg, gt_obj_for_reg = \
        label_creator(places, rotates, size, d_res, h_res, w_res, t, d, h, w,
                      x_min, x_max, y_min, y_max, z_min, z_max, thres_t,
                      anchor_l, anchor_w, anchor_h,
                      anchor_x, anchor_y, anchor_z, scale_label, surround_prob)
    return (feature_input, counter, indexes, gt_obj, gt_reg, gt_obj_for_reg,
            area_mask[None], np.array([indexes.shape[0]]),
            np.array([n_no_empty]))