当前位置:网站首页>The laneatt code is reproduced and tested with the video collected by yourself
The laneatt code is reproduced and tested with the video collected by yourself
2022-07-24 23:18:00 【[email protected]】
Code link :https://github.com/lucastabelini/LaneATT
1. Environment configuration
# The code download
git clone https://github.com/lucastabelini/LaneATT
# New virtual environment
conda create -n laneatt python=3.8 -y
# Activate the virtual environment
conda activate laneatt
# install torch and torchvision
conda install pytorch==1.6 torchvision -c pytorch
# Reinstall necessary python package
pip install -r requirements.txt
# install nms
cd lib/nms; python setup.py install; cd -
2. model training
python main.py train --exp_name my_r18_culane --cfg cfgs/laneatt_culane_resnet18.yml
3. Model testing and its visualization
python main.py test --exp_name my_r18_culane --view all
4. Test with your own video
import logging
import argparse
import torch
from lib.config import Config
from lib.experiment import Experiment
import numpy as np
import cv2
def parse_args():
parser = argparse.ArgumentParser(description="Train lane detector")
parser.add_argument("mode", choices=["train", "test"], help="Train or test?")
parser.add_argument("--exp_name", help="Experiment name", required=True)
parser.add_argument("--cfg", help="Config file")
parser.add_argument("--videoFile", help="Config file")
parser.add_argument("--resume", action="store_true", help="Resume training")
parser.add_argument("--epoch", type=int, help="Epoch to test the model on")
parser.add_argument("--cpu", action="store_true", help="(Unsupported) Use CPU instead of GPU")
parser.add_argument("--save_predictions", action="store_true", help="Save predictions to pickle file")
parser.add_argument("--view", choices=["all", "mistakes"], help="Show predictions")
parser.add_argument("--deterministic",
action="store_true",
help="set cudnn.deterministic = True and cudnn.benchmark = False")
args = parser.parse_args()
if args.cfg is None and args.mode == "train":
raise Exception("If you are training, you have to set a config file using --cfg /path/to/your/config.yaml")
if args.resume and args.mode == "test":
raise Exception("args.resume is set on `test` mode: can't resume testing")
if args.epoch is not None and args.mode == 'train':
raise Exception("The `epoch` parameter should not be set when training")
if args.view is not None and args.mode != "test":
raise Exception('Visualization is only available during evaluation')
if args.cpu:
raise Exception("CPU training/testing is not supported: the NMS procedure is only implemented for CUDA")
return args
def main():
args = parse_args()
exp = Experiment(args.exp_name, args, mode=args.mode)
if args.cfg is None:
cfg_path = exp.cfg_path
else:
cfg_path = args.cfg
cfg = Config(cfg_path)
exp.set_cfg(cfg, override=False)
device = torch.device('cpu') if not torch.cuda.is_available() or args.cpu else torch.device('cuda')
model = cfg.get_model()
model_path = exp.get_checkpoint_path(args.epoch or exp.get_last_checkpoint_epoch())
logging.getLogger(__name__).info('Loading model %s', model_path)
model.load_state_dict(exp.get_epoch_model(args.epoch or exp.get_last_checkpoint_epoch()))
model = model.to(device)
model.eval()
test_parameters = cfg.get_test_parameters()
predictions = []
exp.eval_start_callback(cfg)
videoFile = args.videoFile
cap = cv2.VideoCapture(videoFile)
frameNum = 0
while (cap.isOpened()):
ret, frame = cap.read()
frame = cv2.resize(frame,(640,360))
images = frame/ 255.
frameNum = frameNum + 1
if frameNum % 2 == 0: # Adjust the number of frames
images = torch.from_numpy(images).cuda().float()
images = torch.unsqueeze(images.permute(2, 0, 1),0)
output = model(images, **test_parameters)
prediction = model.decode(output, as_lanes=True)
predictions.extend(prediction)
img = (images[0].cpu().permute(1, 2, 0).numpy() * 255).astype(np.uint8)
img = cv2.resize(img, (640, 360))
img_h, _, _ = img.shape
pad = 0
if pad > 0:
img_pad = np.zeros((360 + 2 * pad, 640 + 2 * pad, 3), dtype=np.uint8)
img_pad[pad:-pad, pad:-pad, :] = img
img = img_pad
for i, l in enumerate(prediction[0]):
points = l.points #<class 'lib.lane.Lane'>
points[:, 0] *= img.shape[1]
points[:, 1] *= img.shape[0]
points = points.round().astype(int)
points += pad
for curr_p, next_p in zip(points[:-1], points[1:]):
frame = cv2.line(frame,
tuple(curr_p),
tuple(next_p),
color=(255, 0, 255),
thickness=3)
cv2.namedWindow("resized", 0) # 0 You can change the window size
cv2.imshow("resized", frame) # Show video
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release
cv2.destroyAllWindows()
if __name__ == '__main__':
main()
Create a new one python file , Copy the code above , Run the following command
python main.py test --exp_name laneatt_r34_tusimple --videoFile /media/gooddz/ New roll / Detect video / Extreme bend scene .mp4
exp_name and videoFile Set it according to your actual needs
版权声明
本文为[[email protected]]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/202/202207201556266637.html
边栏推荐
- Qt | 事件系统 QEvent
- 给生活加点惊喜,做创意生活的原型设计师丨编程挑战赛 x 选手分享
- Talk about how redis handles requests
- Piziheng embedded: the method of making source code into lib Library under MCU Xpress IDE and its difference with IAR and MDK
- Some analysis of slow MySQL query
- "Yuan universe 2086" outsold "San ti" in one-day sales and won the champion of JD books' one-day science fiction list
- Notes of Teacher Li Hongyi's 2020 in-depth learning series 5
- How to speculate on the Internet? Is it safe to speculate on mobile phones
- Process / thread synchronization mechanism
- Entity service is an anti pattern
猜你喜欢

Notes of Teacher Li Hongyi's 2020 in-depth learning series 3

Notes of Teacher Li Hongyi's 2020 in-depth learning series 9

Convex optimization Basics
WPF uses pathgeometry to draw the hour hand and minute hand

《元宇宙2086》单日销量超《三体》 夺得京东图书单日科幻榜冠军

Notes of Teacher Li Hongyi's 2020 in-depth learning series 8

Shardingsphere database sub database sub table introduction

Piziheng embedded: the method of making source code into lib Library under MCU Xpress IDE and its difference with IAR and MDK

用VS Code搞Qt6:编译源代码与基本配置

Xiezhendong: Exploration and practice of digital transformation and upgrading of public transport industry
随机推荐
Li Kou 1184. Distance between bus stops
Burp's thinking from tracing to counteracting
Understanding complexity and simple sorting operation
burp从溯源到反制思路
Oracle中实现对指定数据分组且获取重复次数
Xiezhendong: Exploration and practice of digital transformation and upgrading of public transport industry
一文读懂Elephant Swap的LaaS方案的优势之处
老杜Servlet-JSP
Can the income of CICC securities' new customer financial products reach 6%? How to open an account?
Website resources
VGA display based on FPGA
Value driven provides the core driving force for the transformation of commercial BP - BP realization under business scenarios - Commercial BP sharing
必会面试题:1.浅拷贝和深拷贝_浅拷贝
PGPLSQL中的:=和=
ODBC executes stored procedure to get return value
About constant modifier const
Filter list
RichTextBox save as picture
必会面试题:1.浅拷贝和深拷贝_深拷贝
Collection of common online testing tools