"examples/pytorch/vscode:/vscode.git/clone" did not exist on "13ea9ddb069af447f3624dbcd9a1ac5a94973083"
Commit 9afa546a authored by liyinhao's avatar liyinhao
Browse files

delete augmentation related

parent 24deecb3
import numpy as np
from mmdet.datasets.registry import PIPELINES
def _rotz(t):
"""Rotate About Z.
Rotation about the z-axis.
Args:
t (float): Angle of rotation.
Returns:
rot_mat (ndarray): Matrix of rotation.
"""
c = np.cos(t)
s = np.sin(t)
rot_mat = np.array([[c, -s, 0], [s, c, 0], [0, 0, 1]])
return rot_mat
def _rotate_aligned_boxes(input_boxes, rot_mat):
centers, lengths = input_boxes[:, 0:3], input_boxes[:, 3:6]
new_centers = np.dot(centers, np.transpose(rot_mat))
dx, dy = lengths[:, 0] / 2.0, lengths[:, 1] / 2.0
new_x = np.zeros((dx.shape[0], 4))
new_y = np.zeros((dx.shape[0], 4))
for i, crnr in enumerate([(-1, -1), (1, -1), (1, 1), (-1, 1)]):
crnrs = np.zeros((dx.shape[0], 3))
crnrs[:, 0] = crnr[0] * dx
crnrs[:, 1] = crnr[1] * dy
crnrs = np.dot(crnrs, np.transpose(rot_mat))
new_x[:, i] = crnrs[:, 0]
new_y[:, i] = crnrs[:, 1]
new_dx = 2.0 * np.max(new_x, 1)
new_dy = 2.0 * np.max(new_y, 1)
new_lengths = np.stack((new_dx, new_dy, lengths[:, 2]), axis=1)
return np.concatenate([new_centers, new_lengths], axis=1)
@PIPELINES.register_module()
class IndoorFlipData(object):
"""Indoor Flip Data
Flip point_cloud and groundtruth boxes.
Args:
name (str): name of the dataset.
"""
def __init__(self, name):
assert name in ['scannet', 'sunrgbd']
self.name = name
def __call__(self, results):
point_cloud = results.get('point_cloud', None)
gt_boxes = results.get('gt_boxes', None)
if np.random.random() > 0.5:
# Flipping along the YZ plane
point_cloud[:, 0] = -1 * point_cloud[:, 0]
gt_boxes[:, 0] = -1 * gt_boxes[:, 0]
if self.name == 'sunrgbd':
gt_boxes[:, 6] = np.pi - gt_boxes[:, 6]
results['gt_boxes'] = gt_boxes
if self.name == 'scannet' and np.random.random() > 0.5:
# Flipping along the XZ plane
point_cloud[:, 1] = -1 * point_cloud[:, 1]
gt_boxes[:, 1] = -1 * gt_boxes[:, 1]
results['gt_boxes'] = gt_boxes
results['point_cloud'] = point_cloud
return results
def __repr__(self):
repr_str = self.__class__.__name__
repr_str += '(dataset_name={})'.format(self.name)
return repr_str
@PIPELINES.register_module()
class IndoorRotateData(object):
"""Indoor Rotate Data
Rotate point_cloud and groundtruth boxes.
Args:
name (str): name of the dataset.
"""
def __init__(self, name):
assert name in ['scannet', 'sunrgbd']
self.name = name
self.rot_range = np.pi / 3
def __call__(self, results):
point_cloud = results.get('point_cloud', None)
gt_boxes = results.get('gt_boxes', None)
rot_angle = (np.random.random() *
self.rot_range) - self.rot_range / 2 # -30 ~ +30 degree
rot_mat = _rotz(rot_angle)
point_cloud[:, 0:3] = np.dot(point_cloud[:, 0:3],
np.transpose(rot_mat))
if self.name == 'scannet':
gt_boxes = _rotate_aligned_boxes(gt_boxes, rot_mat)
else:
gt_boxes[:, 0:3] = np.dot(gt_boxes[:, 0:3], np.transpose(rot_mat))
gt_boxes[:, 6] -= rot_angle
results['point_cloud'] = point_cloud
results['gt_boxes'] = gt_boxes
return results
def __repr__(self):
repr_str = self.__class__.__name__
repr_str += '(dataset_name={})'.format(self.name)
return repr_str
import numpy as np
from mmdet3d.datasets.pipelines.indoor_augment import (IndoorFlipData,
IndoorRotateData)
def test_indoor_flip_data():
sunrgbd_flip_data = IndoorFlipData('sunrgbd')
sunrgbd_results = dict()
sunrgbd_results['point_cloud'] = np.array(
[[1.02828765e+00, 3.65790772e+00, 1.97294697e-01, 1.61959505e+00],
[-3.95979017e-01, 1.05465031e+00, -7.49204338e-01, 6.73096001e-01]])
sunrgbd_results['gt_boxes'] = np.array([[
0.213684, 1.036364, -0.982323, 0.61541, 0.572574, 0.872728, 3.07028526
],
[
-0.449953, 1.395455, -1.027778,
1.500956, 1.637298, 0.636364,
-1.58242359
]])
sunrgbd_results = sunrgbd_flip_data(sunrgbd_results)
sunrgbd_point_cloud = sunrgbd_results.get('point_cloud', None)
sunrgbd_gt_boxes = sunrgbd_results.get('gt_boxes', None)
assert sunrgbd_point_cloud.shape == (2, 4)
assert sunrgbd_gt_boxes.shape == (2, 7)
scannet_flip_data = IndoorFlipData('scannet')
scannet_results = dict()
scannet_results['point_cloud'] = np.array(
[[1.6110241e+00, -1.6903955e-01, 5.8115810e-01, 5.9897250e-01],
[1.3978075e+00, 4.2035791e-01, 3.8729519e-01, 4.0510958e-01]])
scannet_results['gt_boxes'] = np.array([[
0.55903838, 0.48201692, 0.65688646, 0.65370704, 0.60029864, 0.5163464
], [
-0.03226406, 1.70392646, 0.60348618, 0.65165804, 0.72084366, 0.64667457
]])
scannet_results = scannet_flip_data(scannet_results)
scannet_point_cloud = scannet_results.get('point_cloud', None)
scannet_gt_boxes = scannet_results.get('gt_boxes', None)
assert scannet_point_cloud.shape == (2, 4)
assert scannet_gt_boxes.shape == (2, 6)
def test_indoor_rotate_data():
sunrgbd_indoor_rotate_data = IndoorRotateData('sunrgbd')
sunrgbd_results = dict()
sunrgbd_results['point_cloud'] = np.array(
[[1.02828765e+00, 3.65790772e+00, 1.97294697e-01, 1.61959505e+00],
[-3.95979017e-01, 1.05465031e+00, -7.49204338e-01, 6.73096001e-01]])
sunrgbd_results['gt_boxes'] = np.array([[
0.213684, 1.036364, -0.982323, 0.61541, 0.572574, 0.872728, 3.07028526
],
[
-0.449953, 1.395455, -1.027778,
1.500956, 1.637298, 0.636364,
-1.58242359
]])
sunrgbd_results = sunrgbd_indoor_rotate_data(sunrgbd_results)
sunrgbd_point_cloud = sunrgbd_results.get('point_cloud', None)
sunrgbd_gt_boxes = sunrgbd_results.get('gt_boxes', None)
assert sunrgbd_point_cloud.shape == (2, 4)
assert sunrgbd_gt_boxes.shape == (2, 7)
scannet_indoor_rotate_data = IndoorRotateData('scannet')
scannet_results = dict()
scannet_results['point_cloud'] = np.array(
[[1.6110241e+00, -1.6903955e-01, 5.8115810e-01, 5.9897250e-01],
[1.3978075e+00, 4.2035791e-01, 3.8729519e-01, 4.0510958e-01]])
scannet_results['gt_boxes'] = np.array([[
0.55903838, 0.48201692, 0.65688646, 0.65370704, 0.60029864, 0.5163464
], [
-0.03226406, 1.70392646, 0.60348618, 0.65165804, 0.72084366, 0.64667457
]])
scannet_results = scannet_indoor_rotate_data(scannet_results)
scannet_point_cloud = scannet_results.get('point_cloud', None)
scannet_gt_boxes = scannet_results.get('gt_boxes', None)
assert scannet_point_cloud.shape == (2, 4)
assert scannet_gt_boxes.shape == (2, 6)
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