Ejemplo n.º 1
0
def get_tusimple(params):
    # augmentation
    flip = Flip()
    translate = Translate()
    rotate = Rotate()
    add_noise = AddGaussianNoise()
    change_intensity = ChangeIntensity()
    resize = Resize(rows=256, cols=512)
    norm_to_1 = NormalizeInstensity()
    whc_to_cwh = TransposeNumpyArray((2, 0, 1))

    train_dataset = DatasetTusimple(
        root_path=params.train_root_url,
        json_files=params.train_json_file,
        transform=transforms.Compose([
            flip, translate, rotate, add_noise, change_intensity, resize,
            norm_to_1, whc_to_cwh
        ]),
    )
    val_dataset = DatasetTusimple(
        params.val_root_url,
        params.val_json_file,
        transform=transforms.Compose([resize, norm_to_1, whc_to_cwh]),
    )
    return train_dataset, val_dataset
Ejemplo n.º 2
0
 def sample(self):
     render = DrawLanemarks(draw_line=True)
     chw_to_hwc = TransposeNumpyArray((1, 2, 0))
     for i in range(len(self.train_dataset)):
         each_sample = self.train_dataset[i]
         print(i, each_sample["image_path"])
         img_src = cv2.imread(each_sample["image_path"])
         each_sample = chw_to_hwc(each_sample)
         img = render(**each_sample)
         cv2.imshow("culane sample", img[:, :, ::-1])
         cv2.imshow("original image", img_src)
         if cv2.waitKey(0) == 27:
             break
Ejemplo n.º 3
0
    def __init__(self, ):
        print("usage examples:")
        print("python -m dataset.culane.test sample")
        print("python -m dataset.culane.test batch")
        print("python -m dataset.culane.test batch shuffle=False")
        flip = Flip(1.0)
        translate = Translate(1.0)
        rotate = Rotate(1.0)
        add_noise = AddGaussianNoise(1.0)
        change_intensity = ChangeIntensity(1.0)
        resize = Resize(rows=256, cols=512)
        hwc_to_chw = TransposeNumpyArray((2, 0, 1))
        norm_to_1 = NormalizeInstensity()

        self.train_dataset = DatasetCollections(transform=transforms.Compose([
            flip, translate, rotate, add_noise, change_intensity, resize,
            norm_to_1, hwc_to_chw
        ]), )
Ejemplo n.º 4
0
    def __init__(self,):
        flip = Flip(1.0)
        translate = Translate(1.0)
        rotate = Rotate(1.0)
        add_noise = AddGaussianNoise(1.0)
        change_intensity = ChangeIntensity(1.0)
        resize = Resize(rows=256, cols=512)
        hwc_to_chw = TransposeNumpyArray((2, 0, 1))
        norm_to_1 = NormalizeInstensity()

        json_file = ['label_data_0313.json', 'label_data_0531.json', 'label_data_0601.json']
        self.train_dataset = DatasetTusimple(root_path="/media/zzhou/data-tusimple/lane_detection/train_set/",
                                             json_files=json_file,
                                             transform=transforms.Compose([flip,
                                                                           translate,
                                                                           rotate,
                                                                           add_noise,
                                                                           change_intensity,
                                                                           resize,
                                                                           norm_to_1,
                                                                           hwc_to_chw]),)
Ejemplo n.º 5
0
    def on_tusimple(self):
        from dataset.tusimple import DatasetTusimple
        from configs.PINet import ParamsTuSimple
        dataset_param = ParamsTuSimple()
        resize = Resize(rows=256, cols=512)
        hwc_to_chw = TransposeNumpyArray((2, 0, 1))
        norm_to_1 = NormalizeInstensity()
        dataset = DatasetTusimple(
            root_path=dataset_param.train_root_url,
            json_files=dataset_param.train_json_file,
            transform=transforms.Compose([resize, norm_to_1, hwc_to_chw]),
        )

        for i in range(len(dataset)):
            sample = dataset[i]
            img_src = cv2.imread(sample["image_path"])
            out_x, out_y = self.detector.test_on_image(
                np.array([sample["image"]]))
            vis_image = draw_points(out_x[0], out_y[0], img_src)
            cv2.imshow("sample", vis_image)
            cv2.imshow("original image", img_src)
            if cv2.waitKey(0) == 27:
                break
Ejemplo n.º 6
0
    def on_culane(self, save=False):
        from dataset.culane import DatasetCULane
        from configs.PINet import ParamsCuLane
        dataset_param = ParamsCuLane()
        resize = Resize(rows=256, cols=512)
        hwc_to_chw = TransposeNumpyArray((2, 0, 1))
        norm_to_1 = NormalizeInstensity()
        dataset = DatasetCULane(
            root_path=dataset_param.train_root_url,
            index_file=dataset_param.train_json_file,
            transform=transforms.Compose([resize, norm_to_1, hwc_to_chw]),
        )

        if save:
            fourcc = cv2.VideoWriter_fourcc(*'MP4V')
            out = cv2.VideoWriter("./output.avi", fourcc, 20.0, (1640, 590))
        else:
            out = None

        for i in range(len(dataset)):
            sample = dataset[i]
            img_src = cv2.imread(sample["image_path"])
            out_x, out_y = self.detector.test_on_image(
                np.array([sample["image"]]))
            vis_image = draw_points(out_x[0],
                                    out_y[0],
                                    img_src,
                                    scale_x=1640 / 512,
                                    scale_y=590 / 256)
            if save:
                out.write(vis_image)
            cv2.imshow("sample", vis_image)
            cv2.imshow("original image", img_src)
            if cv2.waitKey(1) == 27:
                break
        if save:
            out.release()
Ejemplo n.º 7
0
    def __init__(self,):
        print("usage examples:")
        print("python -m dataset.bdd100k.test sample")
        print("python -m dataset.bdd100k.test batch")
        print("python -m dataset.bdd100k.test batch shuffle=False")
        flip = Flip(1.0)
        translate = Translate(1.0)
        rotate = Rotate(1.0)
        add_noise = AddGaussianNoise(1.0)
        change_intensity = ChangeIntensity(1.0)
        resize = Resize(rows=256, cols=512)
        hwc_to_chw = TransposeNumpyArray((2, 0, 1))
        norm_to_1 = NormalizeInstensity()

        self.train_dataset = DatasetBDD100K(root_path="/media/zzhou/data-BDD100K/bdd100k/",
                                            json_files="labels/bdd100k_labels_images_train.json",
                                            transform=transforms.Compose([flip,
                                                                          translate,
                                                                          rotate,
                                                                          add_noise,
                                                                          change_intensity,
                                                                          resize,
                                                                          norm_to_1,
                                                                          hwc_to_chw]), )