Ultra-Fast-Lane-Detection-v2
Ultra-Fast-Lane-Detection-v2 copied to clipboard
单张图片推理车道线不匹配问题
@cfzd if name == "main":
torch.backends.cudnn.benchmark = True
args, cfg = merge_config()
cfg.batch_size = 1
print('setting batch_size to 1 for demo generation')
dist_print('start testing...')
assert cfg.backbone in ['18', '34', '50', '101', '152', '50next', '101next', '50wide', '101wide']
if cfg.dataset == 'CULane':
cls_num_per_lane = 18
elif cfg.dataset == 'Tusimple':
cls_num_per_lane = 56
else:
raise NotImplementedError
net = get_model(cfg)
state_dict = torch.load(cfg.test_model, map_location='cpu')['model']
compatible_state_dict = {}
for k, v in state_dict.items():
if 'module.' in k:
compatible_state_dict[k[7:]] = v
else:
compatible_state_dict[k] = v
net.load_state_dict(compatible_state_dict, strict=False)
net.eval()
img_transforms = transforms.Compose([
transforms.ToPILImage(),
transforms.Resize((cfg.train_height, cfg.train_width)),
transforms.ToTensor(),
transforms.Normalize((0.485, 0.456, 0.406), (0.229, 0.224, 0.225)),
])
img_path = "D:/autodrive/images/00010.png"
img = cv2.imread(img_path)
img_h, img_w = img.shape[0], img.shape[1]
im0 = img.copy()
img = img_transforms(img)
img = img.to('cuda:0')
img = torch.unsqueeze(img, 0)
with torch.no_grad():
pred = net(img)
coords = pred2coords(pred, cfg.row_anchor, cfg.col_anchor, original_image_width=img_w,
original_image_height=img_h)
for lane in coords:
for coord in lane:
cv2.circle(im0, coord, 5, (0, 255, 0), -1)
cv2.imshow('demo', im0)
cv2.waitKey(0)”
这是我改的单张图片的推理,但是检测出的点与车道线匹配不上,似乎是你在加载图片是进行过仿射变换,可以解答一下吗
@Gannis246 我在另外一个issue已经回复了,你可以参考那个回复。
太感谢了,我看了很久,就是没明白cfg.crop_size这个参数是什么意思,这下懂了
------------------ 原始邮件 ------------------ 发件人: @.>; 发送时间: 2022年9月1日(星期四) 晚上8:00 收件人: @.>; 抄送: @.>; @.>; 主题: Re: [cfzd/Ultra-Fast-Lane-Detection-v2] 单张图片推理车道线不匹配问题 (Issue #28)
@Gannis246 我在另外一个issue已经回复了,你可以参考那个回复。
— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>
https://github.com/cfzd/Ultra-Fast-Lane-Detection-v2/issues/18#issuecomment-1234179888
太感谢了,我看了很久,就是没明白cfg.crop_size这个参数是什么意思,这下懂了 … ------------------ 原始邮件 ------------------ 发件人: @.>; 发送时间: 2022年9月1日(星期四) 晚上8:00 收件人: @.>; 抄送: @.>; @.>; 主题: Re: [cfzd/Ultra-Fast-Lane-Detection-v2] 单张图片推理车道线不匹配问题 (Issue #28) @Gannis246 我在另外一个issue已经回复了,你可以参考那个回复。 — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>
所以,现在测试单张图片正常吗?
@Aruen24 正常了 图片预处理部分改成这样
img_transforms = transforms.Compose([
transforms.ToPILImage(),
transforms.Resize((int(cfg.train_height/cfg.crop_ratio), cfg.train_width)),
transforms.ToTensor(),
transforms.Normalize((0.485, 0.456, 0.406), (0.229, 0.224, 0.225)),
])
im0 = img.copy()
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
img_h, img_w = img.shape[0], img.shape[1]
img = img_transforms(img)
img = img[:, -cfg.train_height:, :]
img = img.to('cuda:0')
img = torch.unsqueeze(img, 0)
@Aruen24
效果还是可以的
@Gannis246 你是自己训的模型,用的tusimple_res18?我自己训练的tusimple_res18测试的效果不好。
@Aruen24 我就是用的预训练模型。感觉这个模型泛化性不是很好,近处车道遮挡,压线行驶,大弯道检测不出来,挡风玻璃反光也会偏移
@Aruen24
the code has no problem. if this model is trained by yourself, maybe you have changed the cfg.train_height
or cfg.train_height
.
@Gannis246 I use the pretrained model tusimple_res34.pth. But get the same result.
@Aruen24 I have run every pretrained model and I think culane_res18.pth and culane_res34.pth are best
@Gannis246 so you use my code with tusimple_res34.pth pretrained model test the picture. what is the test result?
@Aruen24
like this
@Gannis246 所以是我的检测代码有问题了,跟你的代码比有哪些不一样呢?
@Aruen24 代码没问题的,其他文件我都没改你就用culane_res18试一下,不行的话换张图试试
------------------ 原始邮件 ------------------ 发件人: "cfzd/Ultra-Fast-Lane-Detection-v2" @.>; 发送时间: 2022年9月2日(星期五) 上午10:29 @.>; @.@.>; 主题: Re: [cfzd/Ultra-Fast-Lane-Detection-v2] 单张图片推理车道线不匹配问题 (Issue #28)
测试一下这张图片看看是否正常
— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>
@Yutong-gannis 请问基于tusimple的训练模型车道线检测飘到天上了,这个问题您解决了吗
@Aruen24 效果还是可以的
请问为什么按照你的代码修改demo.py,基于预训练模型测试tusimple中的单张图片,检测出的点和车道线匹配不上
@Aruen24 @guodaoyi https://github.com/cfzd/Ultra-Fast-Lane-Detection-v2/issues/18#issuecomment-1234179888 如果是飘在天上的话,可能是裁剪的天空范围不对。试试改一下cfg.train_height,cfg.crop_ratio,self.crop_size这几个参数