Download examples/AutoCls3D_ModelNet40/HIRE-Net/data_transforms.py from InternScience/InternAgent: direct link, hf CLI and curl.
- Browser
- Download file 1.4 kB
-
https://huggingface.co/InternScience/InternAgent/resolve/main/examples/AutoCls3D_ModelNet40/HIRE-Net/data_transforms.py
- Command line
-
hf download hf://InternScience/InternAgent/examples/AutoCls3D_ModelNet40/HIRE-Net/data_transforms.py
-
curl -L -o data_transforms.py https://huggingface.co/InternScience/InternAgent/resolve/main/examples/AutoCls3D_ModelNet40/HIRE-Net/data_transforms.py
1.4 kB
| import numpy as np | |
| def random_point_dropout(batch_pc, max_dropout_ratio=0.875): | |
| ''' batch_pc: BxNx3 ''' | |
| for b in range(batch_pc.shape[0]): | |
| dropout_ratio = np.random.random()*max_dropout_ratio # 0~0.875 | |
| drop_idx = np.where(np.random.random((batch_pc.shape[1]))<=dropout_ratio)[0] | |
| if len(drop_idx)>0: | |
| batch_pc[b,drop_idx,:] = batch_pc[b,0,:] # set to the first point | |
| return batch_pc | |
| def random_scale_point_cloud(batch_data, scale_low=0.8, scale_high=1.25): | |
| """ Randomly scale the point cloud. Scale is per point cloud. | |
| Input: | |
| BxNx3 array, original batch of point clouds | |
| Return: | |
| BxNx3 array, scaled batch of point clouds | |
| """ | |
| B, N, C = batch_data.shape | |
| scales = np.random.uniform(scale_low, scale_high, B) | |
| for batch_index in range(B): | |
| batch_data[batch_index,:,:] *= scales[batch_index] | |
| return batch_data | |
| def shift_point_cloud(batch_data, shift_range=0.1): | |
| """ Randomly shift point cloud. Shift is per point cloud. | |
| Input: | |
| BxNx3 array, original batch of point clouds | |
| Return: | |
| BxNx3 array, shifted batch of point clouds | |
| """ | |
| B, N, C = batch_data.shape | |
| shifts = np.random.uniform(-shift_range, shift_range, (B,3)) | |
| for batch_index in range(B): | |
| batch_data[batch_index,:,:] += shifts[batch_index,:] | |
| return batch_data |