Unverified Commit 87b05bae authored by xiliu8006's avatar xiliu8006 Committed by GitHub
Browse files

Fix miss text (#278)

* fixed the bug about miss text files on kitti testing

* add bbox2result_kitti unit test

* add bbox2result_kitti unit test

* add exist_submission_file unit test

* deleted debug code and convert{} to dict()

* add _get_kitti_dataset_config()

* delete print
parent 0a7fb9c7
......@@ -387,15 +387,7 @@ class KittiDataset(Custom3DDataset):
info = self.data_infos[idx]
sample_idx = info['image']['image_idx']
image_shape = info['image']['image_shape'][:2]
box_dict = self.convert_valid_bboxes(pred_dicts, info)
if len(box_dict['bbox']) > 0:
box_2d_preds = box_dict['bbox']
box_preds = box_dict['box3d_camera']
scores = box_dict['scores']
box_preds_lidar = box_dict['box3d_lidar']
label_preds = box_dict['label_preds']
anno = {
'name': [],
'truncated': [],
......@@ -407,6 +399,12 @@ class KittiDataset(Custom3DDataset):
'rotation_y': [],
'score': []
}
if len(box_dict['bbox']) > 0:
box_2d_preds = box_dict['bbox']
box_preds = box_dict['box3d_camera']
scores = box_dict['scores']
box_preds_lidar = box_dict['box3d_lidar']
label_preds = box_dict['label_preds']
for box, box_lidar, bbox, score, label in zip(
box_preds, box_preds_lidar, box_2d_preds, scores,
......@@ -426,6 +424,19 @@ class KittiDataset(Custom3DDataset):
anno = {k: np.stack(v) for k, v in anno.items()}
annos.append(anno)
else:
anno = {
'name': np.array([]),
'truncated': np.array([]),
'occluded': np.array([]),
'alpha': np.array([]),
'bbox': np.zeros([0, 4]),
'dimensions': np.zeros([0, 3]),
'location': np.zeros([0, 3]),
'rotation_y': np.array([]),
'score': np.array([]),
}
annos.append(anno)
if submission_prefix is not None:
curr_file = f'{submission_prefix}/{sample_idx:06d}.txt'
......@@ -438,27 +449,15 @@ class KittiDataset(Custom3DDataset):
print(
'{} -1 -1 {:.4f} {:.4f} {:.4f} {:.4f} '
'{:.4f} {:.4f} {:.4f} '
'{:.4f} {:.4f} {:.4f} {:.4f} {:.4f} {:.4f}'.
format(anno['name'][idx], anno['alpha'][idx],
bbox[idx][0], bbox[idx][1],
bbox[idx][2], bbox[idx][3],
dims[idx][1], dims[idx][2],
'{:.4f} {:.4f} {:.4f} {:.4f} {:.4f} {:.4f}'.format(
anno['name'][idx], anno['alpha'][idx],
bbox[idx][0], bbox[idx][1], bbox[idx][2],
bbox[idx][3], dims[idx][1], dims[idx][2],
dims[idx][0], loc[idx][0], loc[idx][1],
loc[idx][2], anno['rotation_y'][idx],
anno['score'][idx]),
file=f)
else:
annos.append({
'name': np.array([]),
'truncated': np.array([]),
'occluded': np.array([]),
'alpha': np.array([]),
'bbox': np.zeros([0, 4]),
'dimensions': np.zeros([0, 3]),
'location': np.zeros([0, 3]),
'rotation_y': np.array([]),
'score': np.array([]),
})
annos[-1]['sample_idx'] = np.array(
[sample_idx] * len(annos[-1]['score']), dtype=np.int64)
......
import numpy as np
import os
import pytest
import tempfile
import torch
from mmdet3d.core.bbox import LiDARInstance3DBoxes
from mmdet3d.datasets import KittiDataset
def test_getitem():
np.random.seed(0)
def _generate_kitti_dataset_config():
data_root = 'tests/data/kitti'
ann_file = 'tests/data/kitti/kitti_infos_train.pkl'
classes = ['Pedestrian', 'Cyclist', 'Car']
pts_prefix = 'velodyne_reduced'
pipeline = [{
'type': 'LoadPointsFromFile',
'coord_type': 'LIDAR',
'load_dim': 4,
'use_dim': 4,
'file_client_args': {
'backend': 'disk'
}
}, {
'type': 'LoadAnnotations3D',
'with_bbox_3d': True,
'with_label_3d': True,
'file_client_args': {
'backend': 'disk'
}
}, {
'type': 'ObjectSample',
'db_sampler': {
'data_root': 'tests/data/kitti/',
'info_path': 'tests/data/kitti/kitti_dbinfos_train.pkl',
'rate': 1.0,
'prepare': {
'filter_by_difficulty': [-1],
'filter_by_min_points': {
'Pedestrian': 10
}
},
'classes': ['Pedestrian', 'Cyclist', 'Car'],
'sample_groups': {
'Pedestrian': 6
}
}
}, {
'type': 'ObjectNoise',
'num_try': 100,
'translation_std': [1.0, 1.0, 0.5],
'global_rot_range': [0.0, 0.0],
'rot_range': [-0.78539816, 0.78539816]
}, {
'type': 'RandomFlip3D',
'flip_ratio_bev_horizontal': 0.5
}, {
'type': 'GlobalRotScaleTrans',
'rot_range': [-0.78539816, 0.78539816],
'scale_ratio_range': [0.95, 1.05]
}, {
'type': 'PointsRangeFilter',
'point_cloud_range': [0, -40, -3, 70.4, 40, 1]
}, {
'type': 'ObjectRangeFilter',
'point_cloud_range': [0, -40, -3, 70.4, 40, 1]
}, {
'type': 'PointShuffle'
}, {
'type': 'DefaultFormatBundle3D',
'class_names': ['Pedestrian', 'Cyclist', 'Car']
}, {
'type': 'Collect3D',
'keys': ['points', 'gt_bboxes_3d', 'gt_labels_3d']
}]
modality = {'use_lidar': True, 'use_camera': False}
pipeline = [
dict(
type='LoadPointsFromFile',
coord_type='LIDAR',
load_dim=4,
use_dim=4,
file_client_args=dict(backend='disk')),
dict(
type='MultiScaleFlipAug3D',
img_scale=(1333, 800),
pts_scale_ratio=1,
flip=False,
transforms=[
dict(
type='GlobalRotScaleTrans',
rot_range=[0, 0],
scale_ratio_range=[1.0, 1.0],
translation_std=[0, 0, 0]),
dict(type='RandomFlip3D'),
dict(
type='PointsRangeFilter',
point_cloud_range=[0, -40, -3, 70.4, 40, 1]),
dict(
type='DefaultFormatBundle3D',
class_names=['Pedestrian', 'Cyclist', 'Car'],
with_label=False),
dict(type='Collect3D', keys=['points'])
])
]
modality = dict(use_lidar=True, use_camera=False)
split = 'training'
return data_root, ann_file, classes, pts_prefix, pipeline, modality, split
def test_getitem():
np.random.seed(0)
data_root, ann_file, classes, pts_prefix,\
pipeline, modality, split = _generate_kitti_dataset_config()
pipeline = [
dict(
type='LoadPointsFromFile',
coord_type='LIDAR',
load_dim=4,
use_dim=4,
file_client_args=dict(backend='disk')),
dict(
type='LoadAnnotations3D',
with_bbox_3d=True,
with_label_3d=True,
file_client_args=dict(backend='disk')),
dict(
type='ObjectSample',
db_sampler=dict(
data_root='tests/data/kitti/',
info_path='tests/data/kitti/kitti_dbinfos_train.pkl',
rate=1.0,
prepare=dict(
filter_by_difficulty=[-1],
filter_by_min_points=dict(Pedestrian=10)),
classes=['Pedestrian', 'Cyclist', 'Car'],
sample_groups=dict(Pedestrian=6))),
dict(
type='ObjectNoise',
num_try=100,
translation_std=[1.0, 1.0, 0.5],
global_rot_range=[0.0, 0.0],
rot_range=[-0.78539816, 0.78539816]),
dict(type='RandomFlip3D', flip_ratio_bev_horizontal=0.5),
dict(
type='GlobalRotScaleTrans',
rot_range=[-0.78539816, 0.78539816],
scale_ratio_range=[0.95, 1.05]),
dict(
type='PointsRangeFilter',
point_cloud_range=[0, -40, -3, 70.4, 40, 1]),
dict(
type='ObjectRangeFilter',
point_cloud_range=[0, -40, -3, 70.4, 40, 1]),
dict(type='PointShuffle'),
dict(
type='DefaultFormatBundle3D',
class_names=['Pedestrian', 'Cyclist', 'Car']),
dict(
type='Collect3D', keys=['points', 'gt_bboxes_3d', 'gt_labels_3d'])
]
self = KittiDataset(data_root, ann_file, split, pts_prefix, pipeline,
classes, modality)
data = self[0]
......@@ -92,56 +116,10 @@ def test_getitem():
def test_evaluate():
if not torch.cuda.is_available():
pytest.skip('test requires GPU and torch+cuda')
data_root = 'tests/data/kitti'
ann_file = 'tests/data/kitti/kitti_infos_train.pkl'
classes = ['Pedestrian', 'Cyclist', 'Car']
pts_prefix = 'velodyne_reduced'
pipeline = [{
'type': 'LoadPointsFromFile',
'coord_type': 'LIDAR',
'load_dim': 4,
'use_dim': 4,
'file_client_args': {
'backend': 'disk'
}
}, {
'type':
'MultiScaleFlipAug3D',
'img_scale': (1333, 800),
'pts_scale_ratio':
1,
'flip':
False,
'transforms': [{
'type': 'GlobalRotScaleTrans',
'rot_range': [0, 0],
'scale_ratio_range': [1.0, 1.0],
'translation_std': [0, 0, 0]
}, {
'type': 'RandomFlip3D'
}, {
'type': 'PointsRangeFilter',
'point_cloud_range': [0, -40, -3, 70.4, 40, 1]
}, {
'type': 'DefaultFormatBundle3D',
'class_names': ['Pedestrian', 'Cyclist', 'Car'],
'with_label': False
}, {
'type': 'Collect3D',
'keys': ['points']
}]
}]
modality = {'use_lidar': True, 'use_camera': False}
split = 'training'
self = KittiDataset(
data_root,
ann_file,
split,
pts_prefix,
pipeline,
classes,
modality,
)
data_root, ann_file, classes, pts_prefix,\
pipeline, modality, split = _generate_kitti_dataset_config()
self = KittiDataset(data_root, ann_file, split, pts_prefix, pipeline,
classes, modality)
boxes_3d = LiDARInstance3DBoxes(
torch.tensor(
[[8.7314, -1.8559, -1.5997, 0.4800, 1.2000, 1.8900, 0.0100]]))
......@@ -164,42 +142,8 @@ def test_show():
from mmdet3d.core.bbox import LiDARInstance3DBoxes
temp_dir = tempfile.mkdtemp()
data_root = 'tests/data/kitti'
ann_file = 'tests/data/kitti/kitti_infos_train.pkl'
modality = {'use_lidar': True, 'use_camera': False}
split = 'training'
file_client_args = dict(backend='disk')
point_cloud_range = [0, -40, -3, 70.4, 40, 1]
class_names = ['Pedestrian', 'Cyclist', 'Car']
pipeline = [
dict(
type='LoadPointsFromFile',
coord_type='LIDAR',
load_dim=4,
use_dim=4,
file_client_args=file_client_args),
dict(
type='MultiScaleFlipAug3D',
img_scale=(1333, 800),
pts_scale_ratio=1,
flip=False,
transforms=[
dict(
type='GlobalRotScaleTrans',
rot_range=[0, 0],
scale_ratio_range=[1., 1.],
translation_std=[0, 0, 0]),
dict(type='RandomFlip3D'),
dict(
type='PointsRangeFilter',
point_cloud_range=point_cloud_range),
dict(
type='DefaultFormatBundle3D',
class_names=class_names,
with_label=False),
dict(type='Collect3D', keys=['points'])
])
]
data_root, ann_file, classes, pts_prefix,\
pipeline, modality, split = _generate_kitti_dataset_config()
kitti_dataset = KittiDataset(
data_root, ann_file, split=split, modality=modality, pipeline=pipeline)
boxes_3d = LiDARInstance3DBoxes(
......@@ -224,56 +168,10 @@ def test_show():
def test_format_results():
from mmdet3d.core.bbox import LiDARInstance3DBoxes
data_root = 'tests/data/kitti'
ann_file = 'tests/data/kitti/kitti_infos_train.pkl'
classes = ['Pedestrian', 'Cyclist', 'Car']
pts_prefix = 'velodyne_reduced'
pipeline = [{
'type': 'LoadPointsFromFile',
'coord_type': 'LIDAR',
'load_dim': 4,
'use_dim': 4,
'file_client_args': {
'backend': 'disk'
}
}, {
'type':
'MultiScaleFlipAug3D',
'img_scale': (1333, 800),
'pts_scale_ratio':
1,
'flip':
False,
'transforms': [{
'type': 'GlobalRotScaleTrans',
'rot_range': [0, 0],
'scale_ratio_range': [1.0, 1.0],
'translation_std': [0, 0, 0]
}, {
'type': 'RandomFlip3D'
}, {
'type': 'PointsRangeFilter',
'point_cloud_range': [0, -40, -3, 70.4, 40, 1]
}, {
'type': 'DefaultFormatBundle3D',
'class_names': ['Pedestrian', 'Cyclist', 'Car'],
'with_label': False
}, {
'type': 'Collect3D',
'keys': ['points']
}]
}]
modality = {'use_lidar': True, 'use_camera': False}
split = 'training'
self = KittiDataset(
data_root,
ann_file,
split,
pts_prefix,
pipeline,
classes,
modality,
)
data_root, ann_file, classes, pts_prefix,\
pipeline, modality, split = _generate_kitti_dataset_config()
self = KittiDataset(data_root, ann_file, split, pts_prefix, pipeline,
classes, modality)
boxes_3d = LiDARInstance3DBoxes(
torch.tensor(
[[8.7314, -1.8559, -1.5997, 0.4800, 1.2000, 1.8900, 0.0100]]))
......@@ -306,57 +204,56 @@ def test_format_results():
assert np.allclose(result_files[0]['sample_idx'], expected_sample_idx)
def test_bbox2result_kitti():
data_root, ann_file, classes, pts_prefix,\
pipeline, modality, split = _generate_kitti_dataset_config()
self = KittiDataset(data_root, ann_file, split, pts_prefix, pipeline,
classes, modality)
boxes_3d = LiDARInstance3DBoxes(
torch.tensor(
[[8.7314, -1.8559, -1.5997, 0.4800, 1.2000, 1.8900, 0.0100]]))
labels_3d = torch.tensor([
0,
])
scores_3d = torch.tensor([0.5])
result = dict(boxes_3d=boxes_3d, labels_3d=labels_3d, scores_3d=scores_3d)
results = [result]
temp_kitti_result_dir = tempfile.mkdtemp()
det_annos = self.bbox2result_kitti(
results, classes, submission_prefix=temp_kitti_result_dir)
expected_file_path = os.path.join(temp_kitti_result_dir, '000000.txt')
expected_name = np.array(['Pedestrian'])
expected_dimensions = np.array([1.2000, 1.8900, 0.4800])
expected_rotation_y = np.array([0.0100]) - np.pi
expected_score = np.array([0.5])
assert np.all(det_annos[0]['name'] == expected_name)
assert np.allclose(det_annos[0]['rotation_y'], expected_rotation_y)
assert np.allclose(det_annos[0]['score'], expected_score)
assert np.allclose(det_annos[0]['dimensions'], expected_dimensions)
assert os.path.exists(expected_file_path)
os.remove(expected_file_path)
os.removedirs(temp_kitti_result_dir)
temp_kitti_result_dir = tempfile.mkdtemp()
boxes_3d = LiDARInstance3DBoxes(torch.tensor([]))
labels_3d = torch.tensor([])
scores_3d = torch.tensor([])
empty_result = dict(
boxes_3d=boxes_3d, labels_3d=labels_3d, scores_3d=scores_3d)
results = [empty_result]
det_annos = self.bbox2result_kitti(
results, classes, submission_prefix=temp_kitti_result_dir)
expected_file_path = os.path.join(temp_kitti_result_dir, '000000.txt')
assert os.path.exists(expected_file_path)
os.remove(expected_file_path)
os.removedirs(temp_kitti_result_dir)
def test_bbox2result_kitti2d():
data_root = 'tests/data/kitti'
ann_file = 'tests/data/kitti/kitti_infos_train.pkl'
classes = ['Pedestrian', 'Cyclist', 'Car']
pts_prefix = 'velodyne_reduced'
pipeline = [{
'type': 'LoadPointsFromFile',
'coord_type': 'LIDAR',
'load_dim': 4,
'use_dim': 4,
'file_client_args': {
'backend': 'disk'
}
}, {
'type':
'MultiScaleFlipAug3D',
'img_scale': (1333, 800),
'pts_scale_ratio':
1,
'flip':
False,
'transforms': [{
'type': 'GlobalRotScaleTrans',
'rot_range': [-0.1, 0.1],
'scale_ratio_range': [0.9, 1.1],
'translation_std': [0, 0, 0]
}, {
'type': 'RandomFlip3D'
}, {
'type': 'PointsRangeFilter',
'point_cloud_range': [0, -40, -3, 70.4, 40, 1]
}, {
'type': 'DefaultFormatBundle3D',
'class_names': ['Pedestrian', 'Cyclist', 'Car'],
'with_label': False
}, {
'type': 'Collect3D',
'keys': ['points']
}]
}]
modality = {'use_lidar': True, 'use_camera': False}
split = 'training'
self = KittiDataset(
data_root,
ann_file,
split,
pts_prefix,
pipeline,
classes,
modality,
)
data_root, ann_file, classes, pts_prefix,\
pipeline, modality, split = _generate_kitti_dataset_config()
self = KittiDataset(data_root, ann_file, split, pts_prefix, pipeline,
classes, modality)
bboxes = np.array([[[46.1218, -4.6496, -0.9275, 0.5316, 0.5],
[33.3189, 0.1981, 0.3136, 0.5656, 0.5]],
[[46.1366, -4.6404, -0.9510, 0.5162, 0.5],
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment