当前位置:网站首页>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
边栏推荐
- 中金证券新客理财产品收益可以达到百分之六?开户怎么开?
- 【零基础】php代码审计之sql注入
- [cloud native kubernetes] kubernetes cluster advanced resource object staterulesets
- salesforce零基础学习(一百一十六)workflow -&gt; flow浅谈
- burp从溯源到反制思路
- Use and partial explanation of QDIR class
- Notes of Teacher Li Hongyi's 2020 in-depth learning series 9
- How static code analysis works
- Learn AI through detectron2
- Convex optimization Basics
猜你喜欢

Org.json Jsonexception: what about no value for value

背景图和二维码合成

burp从溯源到反制思路

基于Verilog HDL的数字秒表

Baidu online disk +chrome plug-in

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

Value driven provides the core driving force for the transformation of commercial BP - BP realization under business scenarios - Commercial BP sharing

How to propose effective solutions for high-end products? (1 methodology + 2 cases + 1 List)

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

Notes of Teacher Li Hongyi's 2020 in-depth learning series 6
随机推荐
[1184. Distance between bus stops]
HLS编程入门
PHP get thumbnails
Power consumption of chip
聊聊 Redis 是如何进行请求处理
必会面试题:1.浅拷贝和深拷贝_深拷贝
Architecture design of multi live shopping mall
ES6 adds -iterator traversal, for..Of loop
一文读懂Elephant Swap的LaaS方案的优势之处
Trinitycore worldofwarcraft server - registration website
GB、MB、KB分别是什么意思。大小分别是多少
About the word 'don't remember'
《JUC并发编程 - 高级篇》05 -共享模型之无锁 (CAS | 原子整数 | 原子引用 | 原子数组 | 字段更新器 | 原子累加器 | Unsafe类 )
TrinityCore魔兽世界服务器-注册网站
Is it safe for Guosen Securities to open a mobile account
Luogu p2024 [noi2001] food chain
Cross entropy loss
物联网平台返回数据解析时遇到org.json.JSONException: No value for Value怎么办
The rule created by outlook mail is invalid. Possible reasons
Use and partial explanation of QDIR class