1. Construcción del entorno mmdet3d
referencia:
2. Conjunto de datos Waymo
1. Descarga el conjunto de datos de Waymo
Nota: configure Internet científico antes de descargar el conjunto de datos.
Dirección de descarga del sitio web oficial:
https://waymo.com/open/download/ https://waymo.com/open/download/Ingrese a la página como se muestra a continuación
Dado que las versiones 1.4.0 y superiores solo realizan cambios en la segmentación semántica 3D, no es necesario considerar estos problemas de versión para la detección de objetivos 3D. Aquí tomamos la versión 1.4.1 como ejemplo:
Después de ingresar a la página, vemos archived_files/ y individual_files/ . La diferencia es que archived_files/ arriba ha empaquetado los archivos de datos en un paquete comprimido. El siguiente archivo_individual/ separa los archivos de datos uno por uno. El siguiente es el resultado después de la descompresión de archivos_archivados, que es el mismo que el resultado de archivos_individuales/descarga.
Aquí seleccionamos individuales_files/ como ejemplo. Habrá dos métodos de descarga:
1.gsutil
Seleccionamos pruebas, capacitación y validación aquí para descargar y aparecerán las siguientes instrucciones:
Puedes descargar el conjunto de datos llamando al comando gsutil anterior, pero hay algunos puntos a tener en cuenta:
① Configure ubuntu para el acceso científico a Internet: gsutil necesita configurar los servicios relacionados con el proxy con anticipación; de lo contrario, mostrará que el enlace no se puede conectar a la red.
②La red debe funcionar sin problemas: la red debe mantenerse fluida durante la descarga; de lo contrario, se desconectará en el medio y será necesario reiniciarla.
2. Descarga manual
Este método también es el que recomiendo, aunque el proceso es engorroso, no saldrá mal.
Vaya a la carpeta que necesita descargar: testing/ y descárguelos uno por uno, para que no aparezca la interfaz de comando de gsutil.
La capacitación y la validación también se descargan de la misma manera: el formato descargado es un archivo binario *.tfrecord y luego es necesario convertir el formato de datos.
2. Convierta el conjunto de datos de Waymo al conjunto de datos KITTI
Tutorial oficial:
1. Almacenamiento de conjuntos de datos
Copie el conjunto de datos a /mmmdet3d-master/data/waymo/waymo_format. El archivo waymo_format debe ser creado por usted mismo. La carpeta waymo_format se recuperará automáticamente durante la conversión. La estructura general es la siguiente:
Ingrese a la carpeta y los archivos son los siguientes:
2. Cambie el código fuente: create.py
Ubicación: mmdetection3d-master/tools/create_data.py
El proceso de conversión requiere cambiar parte del código fuente para generar ImageSets/training.txt correctos, etc., y colocar la función que genera automáticamente ImageSet en create.py.
def create_ImageSets_img_ids(root_dir):
names_dict=dict()
save_dir = osp.join(root_dir, 'ImageSets/')
if not osp.exists(save_dir): os.mkdir(save_dir)
load_01 =osp.join(root_dir, 'training/calib')
load_2 = osp.join(root_dir, 'testing/calib')
RawNames = os.listdir(load_01) + os.listdir(load_2)
split = [[],[],[]]
for name in RawNames:
if name.endswith('.txt'):
idx = name.replace('.txt', '\n')
split[int(idx[0])].append(idx)
for i in range(3):
split[i].sort()
open(save_dir+'train.txt','w').writelines(split[0])
open(save_dir+'val.txt','w').writelines(split[1])
open(save_dir+'trainval.txt','w').writelines(split[0]+split[1])
open(save_dir+'test.txt','w').writelines(split[2])
Al mismo tiempo, llámalo a través de la función waymo_data_prep:
def waymo_data_prep(root_path,
info_prefix,
version,
out_dir,
workers,
max_sweeps=5):
"""Prepare the info file for waymo dataset.
Args:
root_path (str): Path of dataset root.
info_prefix (str): The prefix of info filenames.
out_dir (str): Output directory of the generated info file.
workers (int): Number of threads to be used.
max_sweeps (int, optional): Number of input consecutive frames.
Default: 5. Here we store pose information of these frames
for later use.
"""
from tools.data_converter import waymo_converter as waymo
splits = ['training', 'validation', 'testing']
for i, split in enumerate(splits):
load_dir = osp.join(root_path, 'waymo_format', split)
if split == 'validation':
save_dir = osp.join(out_dir, 'kitti_format', 'training')
else:
save_dir = osp.join(out_dir, 'kitti_format', split)
converter = waymo.Waymo2KITTI(
load_dir,
save_dir,
prefix=str(i),
workers=workers,
test_mode=(split == 'testing'))
converter.convert()
# Generate waymo infos
out_dir = osp.join(out_dir, 'kitti_format')
create_ImageSets_img_ids(out_dir)
kitti.create_waymo_info_file(
out_dir, info_prefix, max_sweeps=max_sweeps, workers=workers)
GTDatabaseCreater(
'WaymoDataset',
out_dir,
info_prefix,
f'{out_dir}/{info_prefix}_infos_train.pkl',
relative_path=False,
with_mask=False,
num_worker=workers).create()
Finalmente se adjunta el código completo:
# Copyright (c) OpenMMLab. All rights reserved.
import argparse
from os import path as osp
from tools.data_converter import indoor_converter as indoor
from tools.data_converter import kitti_converter as kitti
from tools.data_converter import lyft_converter as lyft_converter
from tools.data_converter import nuscenes_converter as nuscenes_converter
from tools.data_converter.create_gt_database import (
GTDatabaseCreater, create_groundtruth_database)
import os
def kitti_data_prep(root_path,
info_prefix,
version,
out_dir,
with_plane=False):
"""Prepare data related to Kitti dataset.
Related data consists of '.pkl' files recording basic infos,
2D annotations and groundtruth database.
Args:
root_path (str): Path of dataset root.
info_prefix (str): The prefix of info filenames.
version (str): Dataset version.
out_dir (str): Output directory of the groundtruth database info.
with_plane (bool, optional): Whether to use plane information.
Default: False.
"""
kitti.create_kitti_info_file(root_path, info_prefix, with_plane)
kitti.create_reduced_point_cloud(root_path, info_prefix)
info_train_path = osp.join(root_path, f'{info_prefix}_infos_train.pkl')
info_val_path = osp.join(root_path, f'{info_prefix}_infos_val.pkl')
info_trainval_path = osp.join(root_path,
f'{info_prefix}_infos_trainval.pkl')
info_test_path = osp.join(root_path, f'{info_prefix}_infos_test.pkl')
kitti.export_2d_annotation(root_path, info_train_path)
kitti.export_2d_annotation(root_path, info_val_path)
kitti.export_2d_annotation(root_path, info_trainval_path)
kitti.export_2d_annotation(root_path, info_test_path)
create_groundtruth_database(
'KittiDataset',
root_path,
info_prefix,
f'{out_dir}/{info_prefix}_infos_train.pkl',
relative_path=False,
mask_anno_path='instances_train.json',
with_mask=(version == 'mask'))
def nuscenes_data_prep(root_path,
info_prefix,
version,
dataset_name,
out_dir,
max_sweeps=10):
"""Prepare data related to nuScenes dataset.
Related data consists of '.pkl' files recording basic infos,
2D annotations and groundtruth database.
Args:
root_path (str): Path of dataset root.
info_prefix (str): The prefix of info filenames.
version (str): Dataset version.
dataset_name (str): The dataset class name.
out_dir (str): Output directory of the groundtruth database info.
max_sweeps (int, optional): Number of input consecutive frames.
Default: 10
"""
nuscenes_converter.create_nuscenes_infos(
root_path, info_prefix, version=version, max_sweeps=max_sweeps)
if version == 'v1.0-test':
info_test_path = osp.join(root_path, f'{info_prefix}_infos_test.pkl')
nuscenes_converter.export_2d_annotation(
root_path, info_test_path, version=version)
return
info_train_path = osp.join(root_path, f'{info_prefix}_infos_train.pkl')
info_val_path = osp.join(root_path, f'{info_prefix}_infos_val.pkl')
nuscenes_converter.export_2d_annotation(
root_path, info_train_path, version=version)
nuscenes_converter.export_2d_annotation(
root_path, info_val_path, version=version)
create_groundtruth_database(dataset_name, root_path, info_prefix,
f'{out_dir}/{info_prefix}_infos_train.pkl')
def lyft_data_prep(root_path, info_prefix, version, max_sweeps=10):
"""Prepare data related to Lyft dataset.
Related data consists of '.pkl' files recording basic infos.
Although the ground truth database and 2D annotations are not used in
Lyft, it can also be generated like nuScenes.
Args:
root_path (str): Path of dataset root.
info_prefix (str): The prefix of info filenames.
version (str): Dataset version.
max_sweeps (int, optional): Number of input consecutive frames.
Defaults to 10.
"""
lyft_converter.create_lyft_infos(
root_path, info_prefix, version=version, max_sweeps=max_sweeps)
def scannet_data_prep(root_path, info_prefix, out_dir, workers):
"""Prepare the info file for scannet dataset.
Args:
root_path (str): Path of dataset root.
info_prefix (str): The prefix of info filenames.
out_dir (str): Output directory of the generated info file.
workers (int): Number of threads to be used.
"""
indoor.create_indoor_info_file(
root_path, info_prefix, out_dir, workers=workers)
def s3dis_data_prep(root_path, info_prefix, out_dir, workers):
"""Prepare the info file for s3dis dataset.
Args:
root_path (str): Path of dataset root.
info_prefix (str): The prefix of info filenames.
out_dir (str): Output directory of the generated info file.
workers (int): Number of threads to be used.
"""
indoor.create_indoor_info_file(
root_path, info_prefix, out_dir, workers=workers)
def sunrgbd_data_prep(root_path, info_prefix, out_dir, workers, num_points):
"""Prepare the info file for sunrgbd dataset.
Args:
root_path (str): Path of dataset root.
info_prefix (str): The prefix of info filenames.
out_dir (str): Output directory of the generated info file.
workers (int): Number of threads to be used.
"""
indoor.create_indoor_info_file(
root_path,
info_prefix,
out_dir,
workers=workers,
num_points=num_points)
def create_ImageSets_img_ids_1(root_dir):
names_dict=dict()
save_dir = osp.join(root_dir, 'ImageSets/')
if not osp.exists(save_dir): os.mkdir(save_dir)
load_01 =osp.join(root_dir, 'training/calib')
load_2 = osp.join(root_dir, 'testing/calib')
RawNames = os.listdir(load_01) + os.listdir(load_2)
split = [[],[],[]]
for name in RawNames:
if name.endswith('.txt'):
idx = name.replace('.txt', '\n')
split[int(idx[0])].append(idx)
for i in range(3):
split[i].sort()
open(save_dir+'train.txt','w').writelines(split[0])
open(save_dir+'val.txt','w').writelines(split[1])
open(save_dir+'trainval.txt','w').writelines(split[0]+split[1])
open(save_dir+'test.txt','w').writelines(split[2])
def create_ImageSets_img_ids(root_dir):
names_dict = dict()
save_dir = osp.join(root_dir, 'ImageSets/')
if not osp.exists(save_dir): os.mkdir(save_dir)
load_01 = osp.join(root_dir, 'training/calib')
load_2 = osp.join(root_dir, 'testing/calib')
RawNames = os.listdir(load_01) + os.listdir(load_2)
split = [[], [], []]
for name in RawNames:
if name.endswith('.txt'):
idx = name.replace('.txt', '\n')
split[int(idx[0])].append(idx)
for i in range(3):
split[i].sort()
open(save_dir + 'train.txt', 'w').writelines(split[0])
open(save_dir + 'val.txt', 'w').writelines(split[1])
open(save_dir + 'trainval.txt', 'w').writelines(split[0] + split[1])
open(save_dir + 'test.txt', 'w').writelines(split[2])
def waymo_data_prep(root_path,
info_prefix,
version,
out_dir,
workers,
max_sweeps=5):
"""Prepare the info file for waymo dataset.
Args:
root_path (str): Path of dataset root.
info_prefix (str): The prefix of info filenames.
out_dir (str): Output directory of the generated info file.
workers (int): Number of threads to be used.
max_sweeps (int, optional): Number of input consecutive frames.
Default: 5. Here we store pose information of these frames
for later use.
"""
from tools.data_converter import waymo_converter as waymo
splits = ['training', 'validation', 'testing']
for i, split in enumerate(splits):
load_dir = osp.join(root_path, 'waymo_format', split)
if split == 'validation':
save_dir = osp.join(out_dir, 'kitti_format', 'training')
else:
save_dir = osp.join(out_dir, 'kitti_format', split)
converter = waymo.Waymo2KITTI(
load_dir,
save_dir,
prefix=str(i),
workers=workers,
test_mode=(split == 'testing'))
converter.convert()
# Generate waymo infos
out_dir = osp.join(out_dir, 'kitti_format')
create_ImageSets_img_ids(out_dir)
kitti.create_waymo_info_file(
out_dir, info_prefix, max_sweeps=max_sweeps, workers=workers)
GTDatabaseCreater(
'WaymoDataset',
out_dir,
info_prefix,
f'{out_dir}/{info_prefix}_infos_train.pkl',
relative_path=False,
with_mask=False,
num_worker=workers).create()
parser = argparse.ArgumentParser(description='Data converter arg parser')
parser.add_argument('dataset', metavar='kitti', help='name of the dataset')
parser.add_argument(
'--root-path',
type=str,
default='./data/kitti',
help='specify the root path of dataset')
parser.add_argument(
'--version',
type=str,
default='v1.0',
required=False,
help='specify the dataset version, no need for kitti')
parser.add_argument(
'--max-sweeps',
type=int,
default=10,
required=False,
help='specify sweeps of lidar per example')
parser.add_argument(
'--with-plane',
action='store_true',
help='Whether to use plane information for kitti.')
parser.add_argument(
'--num-points',
type=int,
default=-1,
help='Number of points to sample for indoor datasets.')
parser.add_argument(
'--out-dir',
type=str,
default='./data/kitti',
required=False,
help='name of info pkl')
parser.add_argument('--extra-tag', type=str, default='kitti')
parser.add_argument(
'--workers', type=int, default=4, help='number of threads to be used')
args = parser.parse_args()
if __name__ == '__main__':
if args.dataset == 'kitti':
kitti_data_prep(
root_path=args.root_path,
info_prefix=args.extra_tag,
version=args.version,
out_dir=args.out_dir,
with_plane=args.with_plane)
elif args.dataset == 'nuscenes' and args.version != 'v1.0-mini':
train_version = f'{args.version}-trainval'
nuscenes_data_prep(
root_path=args.root_path,
info_prefix=args.extra_tag,
version=train_version,
dataset_name='NuScenesDataset',
out_dir=args.out_dir,
max_sweeps=args.max_sweeps)
test_version = f'{args.version}-test'
nuscenes_data_prep(
root_path=args.root_path,
info_prefix=args.extra_tag,
version=test_version,
dataset_name='NuScenesDataset',
out_dir=args.out_dir,
max_sweeps=args.max_sweeps)
elif args.dataset == 'nuscenes' and args.version == 'v1.0-mini':
train_version = f'{args.version}'
nuscenes_data_prep(
root_path=args.root_path,
info_prefix=args.extra_tag,
version=train_version,
dataset_name='NuScenesDataset',
out_dir=args.out_dir,
max_sweeps=args.max_sweeps)
elif args.dataset == 'lyft':
train_version = f'{args.version}-train'
lyft_data_prep(
root_path=args.root_path,
info_prefix=args.extra_tag,
version=train_version,
max_sweeps=args.max_sweeps)
test_version = f'{args.version}-test'
lyft_data_prep(
root_path=args.root_path,
info_prefix=args.extra_tag,
version=test_version,
max_sweeps=args.max_sweeps)
elif args.dataset == 'waymo':
waymo_data_prep(
root_path=args.root_path,
info_prefix=args.extra_tag,
version=args.version,
out_dir=args.out_dir,
workers=args.workers,
max_sweeps=args.max_sweeps)
elif args.dataset == 'scannet':
scannet_data_prep(
root_path=args.root_path,
info_prefix=args.extra_tag,
out_dir=args.out_dir,
workers=args.workers)
elif args.dataset == 's3dis':
s3dis_data_prep(
root_path=args.root_path,
info_prefix=args.extra_tag,
out_dir=args.out_dir,
workers=args.workers)
elif args.dataset == 'sunrgbd':
sunrgbd_data_prep(
root_path=args.root_path,
info_prefix=args.extra_tag,
num_points=args.num_points,
out_dir=args.out_dir,
workers=args.workers)
3. Iniciar la conversión
Ingrese a la carpeta mmdet3d-master/ y ejecute el comando:
python ./tools/create_data.py waymo --root-path ./data/waymo --out-dir ./data/waymo --extra-tag waymo
Hay dos puntos a tener en cuenta aquí. El primero es agregar waymo después de create_data.py para convertir el conjunto de datos de waymo; el segundo es agregar waymo adicional para cambiar el nombre del pkl final.
El formato del comando es : python ./tools/create_data.py waymo --root-path +el archivo donde se encuentra el conjunto de datos waymo ( archivo tf) --out-dir + ubicación de salida del conjunto de datos --extra-tag waymo
La siguiente interfaz aparecerá como resultado de la ejecución, lo que significa que comienza la conversión:
Finalmente, verifique kitti_format en la carpeta ./data/waymo/:
Una vez que se genera el archivo waymo pkl, la conversión se completa.
4. Empieza a entrenar
Tome los pilares de puntos como ejemplo:
python ./tools/train.py ./configs/pointpillars/hv_pointpillars_secfpn_sbn_2x16_2x_waymo-3d-car.py
El formato de instrucción es : python ./tools/train.py + archivo de modelo (config)
El resultado de la ejecución es:
5. Razonamiento y visualización
Tome los pilares de puntos como ejemplo:
python ./tools/test.py ./configs/pointpillars/hv_pointpillars_secfpn_sbn_2x16_2x_waymo-3d-car.py ./work_dirs/hv_pointpillars_secfpn_sbn_2x16_2x_waymo-3d-car/pv_rcnn.pth --eval 'kitti' --eval-options 'show=True' 'out_dir=./test_results/pointpillars_test_result'
El formato de la instrucción es : python ./tools/test.py + archivo de modelo (config) + archivo de peso pth --eval 'kitti' --eval-options 'show=True' + ubicación de salida
El indicador de evaluación usa kitti, que corresponde al comando: --eval 'kitti'. También puede elegir el método de evaluación de waymo, pero el proceso de instalación es más problemático, por lo que debe intentar instalarlo usted mismo.
Los resultados de la ejecución son los siguientes:
a. Resultados de la inferencia
B. Visualizar resultados