# Fast-Lane_Detection **Repository Path**: linClubs/Fast-Lane-Detection ## Basic Information - **Project Name**: Fast-Lane_Detection - **Description**: 快速车道线检测Fast-Lane_Detection,适用于自己数据集,制作来检测车道线,提供训练,推理,ros推理分支 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 3 - **Created**: 2022-10-27 - **Last Updated**: 2025-04-02 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Ultra-Fast-Lane-Detection PyTorch implementation of the paper "[Ultra Fast Structure-aware Deep Lane Detection](https://arxiv.org/abs/2004.11757)". --- # 1 运行demo_avi ## 1.1 图森的数据格式 1. 修改configs/tusimple.py + data_root = './Tusimple' + log_path = './log' 2. 修改`./utils/common.py`的`get_args()`函数 ~~~python def get_args(): parser = argparse.ArgumentParser() parser.add_argument('config', help = 'path to config file') # parser.add_argument('config', help='path to config file', default="./configs/tusimple.py") parser.add_argument('--local_rank', type=int, default=0) parser.add_argument('--dataset', default = None, type = str) parser.add_argument('--data_root', default = None, type = str) parser.add_argument('--epoch', default = 20, type = int) parser.add_argument('--batch_size', default = 1, type = int) parser.add_argument('--optimizer', default = None, type = str) parser.add_argument('--learning_rate', default = None, type = float) parser.add_argument('--weight_decay', default = None, type = float) parser.add_argument('--momentum', default = None, type = float) parser.add_argument('--scheduler', default = None, type = str) parser.add_argument('--steps', default = None, type = int, nargs='+') parser.add_argument('--gamma', default = None, type = float) parser.add_argument('--warmup', default = None, type = str) parser.add_argument('--warmup_iters', default = None, type = int) parser.add_argument('--backbone', default = None, type = str) parser.add_argument('--griding_num', default = None, type = int) parser.add_argument('--use_aux', default = None, type = str2bool) parser.add_argument('--sim_loss_w', default = None, type = float) parser.add_argument('--shp_loss_w', default = None, type = float) parser.add_argument('--note', default = None, type = str) parser.add_argument('--log_path', default = None, type = str) parser.add_argument('--finetune', default = None, type = str) parser.add_argument('--resume', default = None, type = str) parser.add_argument('--test_model', default = None, type = str) parser.add_argument('--test_work_dir', default = None, type = str) parser.add_argument('--num_lanes', default = None, type = int) parser.add_argument('--auto_backup', action='store_true', help='automatically backup current code in the log path') ~~~ --- 3. 主要是这2个参数,必须给,其他有默认值 ~~~sh --config --test_model ~~~ 4. 运行 ~~~python python demo.py configs/tusimple.py --test_model tusimple_18.pth ~~~ --- ## 1.2 CULane数据格式 ~~~python python demo.py configs/culane.py --test_model culane_18.pth ~~~ ## 1.3 预训练权重 | Dataset | Metric paper | Metric This repo | Avg FPS on GTX 1080Ti | Model | |:--------:|:------------:|:----------------:|:-------------------:|:-----------:| | Tusimple | 95.87 | 95.82 | 306 | [GoogleDrive](https://drive.google.com/file/d/1WCYyur5ZaWczH15ecmeDowrW30xcLrCn/view?usp=sharing)/[BaiduDrive(code:bghd)](https://pan.baidu.com/s/1Fjm5yVq1JDpGjh4bdgdDLA) | | CULane | 68.4 | 69.7 | 324 | [GoogleDrive](https://drive.google.com/file/d/1zXBRTw50WOzvUp6XKsi8Zrk3MUC3uFuq/view?usp=sharing)/[BaiduDrive(code:w9tw)](https://pan.baidu.com/s/19Ig0TrV8MfmFTyCvbSa4ag) | ## 1.4 运行自己的视频流 ~~~sh python demo_avi.py configs/tusimple.py --test_model ./weights/tusimple_18.pth ~~~ + cpu版本 ~~~sh python demo_cpu.py configs/tusimple.py --test_model ./weights/tusimple_18.pth ~~~ --- # 2 训练 ## 2.1 训练tusimple数据集 先运行`./scripts/convert_tusimple.py`生成数据集 需要修改2个地方`convert_tusimple.py` ['label.json']为训练集的标注json格式的,与['test.json']为测试集的json标注, 直接将自己用labelme标注的json格式文件,直接改名就行。 运行后在数据集路径生成train_gt.txt与test.txt文件 ~~~ python # train set names, line_txt = get_tusimple_list(args.root,['label.json']) # testing set names,line_txt = get_tusimple_list(args.root, ['test.json']) ~~~ + 运行时会报错: 1. `Initializing libiomp5md.dll, but found libiomp5md.dll already initialized` 在import torch之前,加入下面代码: ~~~python import os os.environ["KMP_DUPLICATE_LIB_OK"]="TRUE" ~~~ 2. `RuntimeError: DataLoader worker (pid(s) XXX) exited unexpectedly` 3. 多线程的原因 将`./data/dataloader.py`中num_workers改成0 ~~~python train_loader = torch.utils.data.DataLoader(train_dataset, batch_size=batch_size, sampler = sampler, num_workers=0) loader = torch.utils.data.DataLoader(test_dataset, batch_size=batch_size, sampler = sampler, num_workers=0) ~~~ + --- + # 3 训练自己的数据集 ## 3.1 制作数据集 准备图片采用图森格式图片大小为1280*720 datasets目录下,pic为图片路径,新建空的json目录存放标签,如下所示 ![](weights/1.jpg) 1. 安装labelme制作 ~~~ pip install labelme ~~~ 2. 启动labelme ~~~ labelme ~~~ 修改3个file里面的选项 + open dir:选择pic目录,就是图片目录 + save automatically:选中一次就行,可以自动保存json + Change output Dir :选择json目录,就是标注后json保存位置 ## 3.2 标注完成后,生成数据集 标注完后,pic为图片数据,json问标签数据 1. 运行`data_process/json2instance_2.py`生成标注后的图像 ~~~python python data_process/json2instance_2.py ~~~ 可以`data_process/json2instance_2.py`中的下面代码,查看标注图像 + color=(ind+1) * 50 + 20, 查看标注图像用这个 + thickness=4 标注的线宽,根据实际调整 + color=(ind + 1,ind + 1,ind + 1) 训练时用这个,不要会报错 ~~~python # 画线,如果给图片加上颜色,训练会报错 cv2.polylines(instance_image, [contours], isClosed=False, color=(ind+1) * 50 + 20, thickness=4) # cv2.polylines(instance_image, [contours], isClosed=False, color=(ind + 1,ind + 1,ind + 1), thickness=4) ~~~ ![](weights/2.png) 训练时出现: ![](weights/3.png) 将`data_process/json2instance_2.py`的对应代码改成如下。 重新运行data_process/json2instance_2.py ~~~python # 画线,如果给图片加上颜色,训练会报错 # cv2.polylines(instance_image, [contours], isClosed=False, color=(ind+1) * 50 + 20, thickness=4) cv2.polylines(instance_image, [contours], isClosed=False, color=(ind + 1,ind + 1,ind + 1), thickness=4) ~~~ ## 3.3 训练 ~~~python python train_alian.py ~~~ + --- --- + The evaluation code is modified from [SCNN](https://github.com/XingangPan/SCNN) and [Tusimple Benchmark](https://github.com/TuSimple/tusimple-benchmark). Caffe model and prototxt can be found [here](https://github.com/Jade999/caffe_lane_detection). # Install Please see [INSTALL.md](./INSTALL.md) # Get started First of all, please modify `data_root` and `log_path` in your `configs/culane.py` or `configs/tusimple.py` config according to your environment. - `data_root` is the path of your CULane dataset or Tusimple dataset. - `log_path` is where tensorboard logs, trained models and code backup are stored. ***It should be placed outside of this project.*** *** For single gpu training, run ```Shell python train.py configs/path_to_your_config ``` For multi-gpu training, run ```Shell sh launch_training.sh ``` or ```Shell python -m torch.distributed.launch --nproc_per_node=$NGPUS train.py configs/path_to_your_config ``` If there is no pretrained torchvision model, multi-gpu training may result in multiple downloading. You can first download the corresponding models manually, and then restart the multi-gpu training. Since our code has auto backup function which will copy all codes to the `log_path` according to the gitignore, additional temp file might also be copied if it is not filtered by gitignore, which may block the execution if the temp files are large. So you should keep the working directory clean. *** Besides config style settings, we also support command line style one. You can override a setting like ```Shell python train.py configs/path_to_your_config --batch_size 8 ``` The ```batch_size``` will be set to 8 during training. *** To visualize the log with tensorboard, run ```Shell tensorboard --logdir log_path --bind_all ``` # Trained models We provide two trained Res-18 models on CULane and Tusimple. | Dataset | Metric paper | Metric This repo | Avg FPS on GTX 1080Ti | Model | |:--------:|:------------:|:----------------:|:-------------------:|:-----------:| | Tusimple | 95.87 | 95.82 | 306 | [GoogleDrive](https://drive.google.com/file/d/1WCYyur5ZaWczH15ecmeDowrW30xcLrCn/view?usp=sharing)/[BaiduDrive(code:bghd)](https://pan.baidu.com/s/1Fjm5yVq1JDpGjh4bdgdDLA) | | CULane | 68.4 | 69.7 | 324 | [GoogleDrive](https://drive.google.com/file/d/1zXBRTw50WOzvUp6XKsi8Zrk3MUC3uFuq/view?usp=sharing)/[BaiduDrive(code:w9tw)](https://pan.baidu.com/s/19Ig0TrV8MfmFTyCvbSa4ag) | For evaluation, run ```Shell mkdir tmp # This a bad example, you should put the temp files outside the project. python test.py configs/culane.py --test_model path_to_culane_18.pth --test_work_dir ./tmp python test.py configs/tusimple.py --test_model path_to_tusimple_18.pth --test_work_dir ./tmp ``` Same as training, multi-gpu evaluation is also supported. # Visualization We provide a script to visualize the detection results. Run the following commands to visualize on the testing set of CULane and Tusimple. ```Shell python demo.py configs/culane.py --test_model path_to_culane_18.pth # or python demo.py configs/tusimple.py --test_model path_to_tusimple_18.pth ``` Since the testing set of Tusimple is not ordered, the visualized video might look bad and we **do not recommend** doing this. # Speed To test the runtime, please run ```Shell python speed_simple.py # this will test the speed with a simple protocol and requires no additional dependencies python speed_real.py # this will test the speed with real video or camera input ``` It will loop 100 times and calculate the average runtime and fps in your environment. # Citation ```BibTeX @InProceedings{qin2020ultra, author = {Qin, Zequn and Wang, Huanyu and Li, Xi}, title = {Ultra Fast Structure-aware Deep Lane Detection}, booktitle = {The European Conference on Computer Vision (ECCV)}, year = {2020} } ``` # Thanks Thanks zchrissirhcz for the contribution to the compile tool of CULane, KopiSoftware for contributing to the speed test, and ustclbh for testing on the Windows platform.