当前位置:网站首页>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
边栏推荐
- Salesforce zero foundation learning (116) workflow - & gt; On flow
- Zheng Huijuan: Research on application scenarios and evaluation methods of data assets based on the unified market
- About the word 'don't remember'
- Network Security Learning (III) basic DOS commands
- 关于板载继电器供电不足引起不能吸合的问题
- 用VS Code搞Qt6:编译源代码与基本配置
- Shardingsphere database sub database sub table introduction
- 郑慧娟:基于统一大市场的数据资产应用场景与评估方法研究
- 聊聊 Redis 是如何进行请求处理
- 凸优化基础知识
猜你喜欢

Alibaba cloud SSL certificate

salesforce零基础学习(一百一十六)workflow -&gt; flow浅谈

认识复杂度和简单排序运算

About constant modifier const

Network Security Learning (V) DHCP

Network Security Learning (II) IP address

Org.json Jsonexception: what about no value for value

Paper notes: accurate causal influence on discrete data

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

Upgrade the jdbc driver to version 8.0.28 and connect to the pit record of MySQL
随机推荐
Upgrade the jdbc driver to version 8.0.28 and connect to the pit record of MySQL
JDBC 驱动升级到 Version 8.0.28 连接 MySQL 的踩坑记录
[1184. Distance between bus stops]
给生活加点惊喜,做创意生活的原型设计师丨编程挑战赛 x 选手分享
RichTextBox operation
yolov5
Pointrender parsing
VC prompts to recompile every time you press F5 to run
Browser cache
理财产品可以达到百分之6的,我想要开户买理财产品
中金证券新客理财产品收益可以达到百分之六?开户怎么开?
郑慧娟:基于统一大市场的数据资产应用场景与评估方法研究
Backgroundworker enables time-consuming operations without affecting interface response
salesforce零基础学习(一百一十六)workflow -&gt; flow浅谈
ASP.NET Core 6.0 基于模型验证的数据验证
Mandatory interview questions: 1. shallow copy and deep copy_ Deep copy
[cloud native kubernetes] kubernetes cluster advanced resource object staterulesets
Add a little surprise to life and be a prototype designer of creative life -- sharing with X contestants in the programming challenge
VGA display based on FPGA
Shardingsphere database sub database sub table introduction