pointpillars代码阅读-----架构篇Brief
 ⽬前已经理论知识丰富,但是实践很少,因此决定在这两周内,做以下两件事:阅读pointpillars代码,侧重点在理解怎么在nuscence上进⾏多⽬标检测的。并写笔记。
完成以下⽹络的搭建:(也即是是voxel的检测)
这⼀部分主要是⼤体架构,后续的博客是针对细节的博客。
1 pointpillars代码
1.1 简单介绍
这⾥是
这个版本已经升级到了V2.0,也就是加⼊了nuscence的检测任务,同时SECOND的稀疏卷积也改变成作者的写法。kitti数据集在官⽹上下载就⾏了;
这⾥。
所有的代码如下:其中second是最重要的,核⼼代码在second/pytorch下⾯
1.2 代码阅读
写在前⾯
(1)博主从未⾃⼰搭过⽹络,下⾯的理解仅仅是个⼈的思考,如果有问题,希望⼤家指出。
(2)博主⽬前想要研究该代码是如何进⾏多类检测任务的,因此选择的config⽂件为:fig
运⾏程序:
python create_data.py kitti_data_prep --data_path=KITTI_DATASET_ROOT
然后开始debug:
部分1:创建模型保存地址,读取预处理后的数据形式:
model_dir = str(Path(model_dir).resolve())
if create_folder:
if Path(model_dir).exists():
model_dir = ate_folder(model_dir)
model_dir = Path(model_dir)
if not resume and ists():
raise ValueError("model dir exists and you don't specify resume.")
model_dir.mkdir(parents=True, exist_ok=True)
if result_path is None:
result_path = model_dir / 'results'
config_file_bkp = "fig"
if isinstance(config_path, str):
# directly provide a config object. this usually used
# when you want to train with several different parameters in
# one script.
config = pipeline_pb2.TrainEvalPipelineConfig()
with open(config_path, "r") as f:
proto_str = f.read()
text_format.Merge(proto_str, config)
else:
config = config_path
proto_str = text_format.MessageToString(config, indent=2)
with (model_dir / config_file_bkp).open("w") as f:
f.write(proto_str)
input_cfg = ain_input_reader
eval_input_cfg = config.eval_input_reader
model_cfg = del.second
train_cfg = ain_config
第⼆部分:建⽴⽹络
net = build_network(model_cfg, measure_time).to(device)
第三部分:加载检测⽬标⽂件和voxel⽣成器
target_assigner = net.target_assigner
voxel_generator = net.voxel_generator
[car,pedestrain,cyclist,van]
这⾥的分类⽬标包括有,同时的四类检测问题,以前分别对⼀种做检测时,需要设置同⼀种的anchor_size,然后只需要做⼆分类任务,如果是多类检测,应该需要如上四种不同类别的anchor和不同的size,在随后的检测时需要输出其对应的类别。
第四部分:设置优化器和损失函数
optimizer_cfg = train_cfg.optimizer
loss_scale = train_cfg.loss_scale_factor
fastai_optimizer = optimizer_builder.build(
optimizer_cfg,
net,
mixed=False,
loss_scale=loss_scale)
损失函数是multi-loss的形式,包含了回归损失和分类损失,分类损失采⽤的是focal-loss
第五部分:输⼊数据的准备
dataset = input_reader_builder.build(
input_cfg,
model_cfg,
training=True,
voxel_generator=voxel_generator,
target_assigner=target_assigner,
multi_gpu=multi_gpu)
dataloader = torch.utils.data.DataLoader(
dataset,
batch_size=input_cfg.batch_size * num_gpu,
shuffle=True,
num_workers=input_cfg.preprocess.num_workers * num_gpu,
pin_memory=False,
collate_fn=collate_fn,
worker_init_fn=_worker_init_fn,
drop_last=not multi_gpu)输出:remain number of infos: 3712;在前⾯预处理中,作者把训练数据和验证数据差不多55分;
第六部分:训练
for example in dataloader:
lr_scheduler._global_step())
。。。
(1)example 数据包括以下的内容。其中batch_size=3,很多shape前⾯的3也就是batch_size。
元素shape 含义
voxels [54786,5,4]最⼤含有54786个voxels(54786是3个batch所有点的个数),每个点中最多5个点,每个点4
个维度信息
num_points [54786,]⼀个batch中所有点的个数
coordinates [54786,4]每⼀个点对应的voxel坐标,4表⽰的是[bs,x,y,z]
num_voxels [3,1]
稀疏矩阵的参数[41,1280,1056]metrics list类型,长度为3,
[gen_time,prep_time]
衡量时间calib dict类型,长度为3,[rect,Trv2c,P2]
⼆维到点云变换矩阵anchors [3,168960,7]
3是bs,168960=1601328*4,7是回归维度gt_names [67,]
这⾥的67的含义是在这个batch中有67个gt,names={car,cyslist,pedestrain,car}labels [3,168960]
每⼀个anchor的lable reg_targes [3,168960,7]
reg所对应的真实的gt
importance [3,1689660]
metadata list,长度为3解释⼀下16980的含义,最终经过中间层后提取的feature_map ⼤⼩是这⾥的8表⽰两个⽅向*4个类别,然后每⼀种anchor预测得到⼀个回归值和⼀个分类值,然后也就是;就是说,这个值是预先设定好的。
[3,8,130,132]8×130×132=168960
⼀些重要的函数如下
python怎么读文件example_torch = example_convert_to_torch(example, float_dtype)
上⾯的函数把加载的example数据都转到gpu上,内容和变量example是⼀样的。
ret_dict = net_parallel(example_torch)
上述函数net_parallel是⼀个net,结构复杂,内容截图如下,重要的部分
(1)在models中,包含了特征提取层,特征中间层,rpn等⼀些loss
(2)上诉的这⼀句应该就是经过了⼀次这个⽹络。得到了ret_dict。
(3)ret_dict的内容如下图所⽰,可以看到含有很多的loss。做成表格看⼀下对应的shape如下:
attributes shape含义

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。