Posted in

基于飞桨框架的稀疏计算使用指南_AI阅读总结 — 包阅AI

包阅导读总结

思维导图:

文章地址:https://mp.weixin.qq.com/s/zHi9ys5flAwCMe9sfPe49A

文章来源:mp.weixin.qq.com

作者:全栈布局的

发布时间:2024/8/6 10:03

语言:中文

总字数:7198字

预计阅读时间:29分钟

评分:81分

标签:飞桨框架,稀疏计算,深度学习,稀疏ResNet,3D残差网络


以下为原文内容

本内容来源于用户推荐转载,旨在分享知识与观点,如有侵权请联系删除 联系邮箱 media@ilingban.com

class SparseResNet3D(paddle.nn.Layer):    """ The main Sparse 3D ResNet class, designed for processing voxelized point cloud data."""        def __init__(self, in_channels, voxel_size, point_cloud_range):        super(SparseResNet3D, self).__init__()
self.conv_input = paddle.nn.Sequential( nn.SubmConv3D(in_channels, 16, 3, bias_attr=False, key='res0'), nn.BatchNorm(16), nn.ReLU())
self.conv1 = paddle.nn.Sequential( SparseBasicBlock(16, 16, indice_key='res0'), SparseBasicBlock(16, 16, indice_key='res0'),)
self.conv2 = paddle.nn.Sequential( nn.Conv3D(16, 32, 3, 2, padding=1, bias_attr=False), nn.BatchNorm(32), nn.ReLU(), SparseBasicBlock(32, 32, indice_key='res1'), SparseBasicBlock(32, 32, indice_key='res1'),)
self.conv3 = paddle.nn.Sequential( nn.Conv3D(32, 64, 3, 2, padding=1, bias_attr=False), nn.BatchNorm(64), nn.ReLU(), SparseBasicBlock(64, 64, indice_key='res2'), SparseBasicBlock(64, 64, indice_key='res2'),)
self.conv4 = paddle.nn.Sequential( nn.Conv3D(64, 128, 3, 2, padding=[0, 1, 1], bias_attr=False), nn.BatchNorm(128), nn.ReLU(), SparseBasicBlock(128, 128, indice_key='res3'), SparseBasicBlock(128, 128, indice_key='res3'),)
self.extra_conv = paddle.nn.Sequential( nn.Conv3D(128, 128, (3, 1, 1), (2, 1, 1), bias_attr=False), nn.BatchNorm(128), nn.ReLU(),)
point_cloud_range = np.array(point_cloud_range, dtype=np.float32) voxel_size = np.array(voxel_size, dtype=np.float32) grid_size = (point_cloud_range[3:] - point_cloud_range[:3]) / voxel_size grid_size = np.round(grid_size).astype(np.int64) self.sparse_shape = np.array(grid_size[::-1]) + [1, 0, 0] self.in_channels = in_channels self.init_weight()
def init_weight(self): """ Initialize weights for convolutional layers and batch normalization layers.""" for layer in self.sublayers(): if isinstance(layer, (nn.Conv3D, nn.SubmConv3D)): param_init.reset_parameters(layer) if isinstance(layer, nn.BatchNorm): param_init.constant_init(layer.weight, value=1) param_init.constant_init(layer.bias, value=0)
def forward(self, voxel_features, coors, batch_size): """ The forward pass for processing input voxel features and coordinates.""" shape = [batch_size] + list(self.sparse_shape) + [self.in_channels] sp_x = sparse.sparse_coo_tensor( coors.transpose((1, 0)), voxel_features, shape=shape, stop_gradient=False)
x = self.conv_input(sp_x) x_conv1 = self.conv1(x) x_conv2 = self.conv2(x_conv1) x_conv3 = self.conv3(x_conv2) x_conv4 = self.conv4(x_conv3)
out = self.extra_conv(x_conv4)
out = out.to_dense() out = paddle.transpose(out, perm=[0, 4, 1, 2, 3]) N, C, D, H, W = out.shape out = paddle.reshape(out, shape=[N, C * D, H, W]) return out