-
Notifications
You must be signed in to change notification settings - Fork 294
【Hackathon 6th Article No.6】稀疏ResNet的学习心得 #883
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
||
PaddlePaddle 提供了完整的支持来创建和操作 COO 和 CSR 格式的稀疏张量。以下是使用 PaddlePaddle 创建和操作这些张量的具体方法。 | ||
|
||
 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里的图片有吗
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
上传啦,辛苦老师再看看
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
看一下其他的图片写法
## 1. COO(Coordinate Format) | ||
在 COO 格式中,只记录非零元素的位置和值。这种格式由三个主要组件组成:`indices`、`values` 和 `shape`。`indices` 是一个二维数组,其中的每一列代表一个非零元素的坐标;`values` 存储对应的非零元素值;`shape` 则描述了张量的维度。 | ||
|
||
 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这种形式可以正常预览吗,一般是把图片也需要提交过来,看一下其他的写法
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好滴,已学习图片写法,麻烦老师再看看
## 2. CSR(Compressed Sparse Row Format) | ||
CSR 格式是一种更为紧凑的稀疏表示,专为快速的行访问和矩阵乘法运算优化。在 CSR 中,通过三个数组 `crows`、`cols` 和 `values` 来表示稀疏矩阵。`crows` 存储每一行第一个非零元素的索引,`cols` 存储非零元素的列索引,而 `values` 则直接存储这些非零元素的值。 | ||
|
||
 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
看一下其他的图片写法
- 这是一种常用的稀疏表示格式,其中非零元素通过其坐标列表进行存储。 | ||
- 使用 `paddle.sparse.sparse_coo_tensor(indices, values, shape)` 可以创建 COO 格式的稀疏张量,其中 `indices` 是一个二维整数张量,指示非零元素的坐标;`values` 是一个张量,包含与 `indices` 对应的值;`shape` 是一个定义张量形状的整数列表或张量。 | ||
|
||
2. **转换功能**: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个不是 CSR 格式吗
|
||
PaddlePaddle 提供了完整的支持来创建和操作 COO 和 CSR 格式的稀疏张量。以下是使用 PaddlePaddle 创建和操作这些张量的具体方法。 | ||
|
||
 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
看一下其他的图片写法
|
||
对于 `sparse_coo_tensor` 和 `sparse_csr_tensor` 函数,存在一些共通的参数,这些参数允许用户指定如何构建和处理稀疏张量: | ||
|
||
1. **indices, crows, cols (list|tuple|ndarray|Tensor)**: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个不是共通参数吧,下面的特定参数也进行了描述的
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已调整到后面
- 这些层专为稀疏数据优化,减少了对零值的计算和存储,从而提高了性能和效率。 | ||
|
||
2. **批归一化层**: | ||
- `BatchNorm3D`: 用于3D数据的批归一化层,支持与稀疏卷积层配合使用。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
写一下API的全名吧
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好嘞
|
||
PaddlePaddle 在 `paddle.sparse.nn` 模块中提供了专门针对稀疏数据设计的神经网络层,这些层包括: | ||
|
||
1. **稀疏卷积层**: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
写一下API的全名吧
- `BatchNorm3D`: 用于3D数据的批归一化层,支持与稀疏卷积层配合使用。 | ||
|
||
3. **激活函数**: | ||
- 如 `ReLU`,支持在稀疏数据路径中使用,与常规的激活函数使用方法相同。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
写一下API的全名吧
x = sparse.sparse_coo_tensor(coords, values, shape) | ||
|
||
# 实例化模型 | ||
model |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
model没有实例化
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已完善补充
``` | ||
输出: | ||
|
||
 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
图片写法更正
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里的图片是代码输出结果截图,学习图片写法的过程中,发现都是放的为文字版运行结果,已将结果文字复制进来
已全部修改,辛苦老师再看看 |
|
||
2. **CSR格式(Compressed Sparse Row)**: | ||
- 这是另一种常用的稀疏表示格式,主要用于优化行访问的性能,其中非零元素通过行的压缩方式进行存储。 | ||
- 使用 `paddle.sparse.sparse_csr_tensor(crow_indices, col_indices, values, shape)` 可以创建 CSR 格式的稀疏张量,其中 `crow_indices` 是一个一维整数张量,指示每一行的起始非零元素在 `values` 中的位置;`col_indices` 是一个一维整数张量,指示每个非零元素的列索引;`values` 是一个张量,包含所有非零元素的值;`shape` 是一个定义张量形状的整数列表或张量。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个API的签名不太对
- 这是另一种常用的稀疏表示格式,主要用于优化行访问的性能,其中非零元素通过行的压缩方式进行存储。 | ||
- 使用 `paddle.sparse.sparse_csr_tensor(crow_indices, col_indices, values, shape)` 可以创建 CSR 格式的稀疏张量,其中 `crow_indices` 是一个一维整数张量,指示每一行的起始非零元素在 `values` 中的位置;`col_indices` 是一个一维整数张量,指示每个非零元素的列索引;`values` 是一个张量,包含所有非零元素的值;`shape` 是一个定义张量形状的整数列表或张量。 | ||
|
||
3. **转换功能**: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sparse与Dense互转
- 对于 CSR 格式,`crows` 和 `cols` 分别表示行索引的开始和非零元素的列索引。 | ||
- 这些参数可以是 Python 的 list 或 tuple,也可以是 NumPy ndarray 或 Paddle Tensor。 | ||
|
||
**COO 格式** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这一段应该不需要了,和上面是重复内容
# 二、Paddle稀疏张量支持 | ||
|
||
|
||
PaddlePaddle 支持多种类型的稀疏张量,主要包括: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
感觉这一段内容和下面的53~128是重复的,可以精简下内容
|
||
输出: | ||
```python | ||
Tensor(shape=[1, 1, 100, 100, 64], dtype=paddle.float32, place=Place(cpu), stop_gradient=False, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个采用 省略号 把下面的values精简下吧
|
||
|
||
|
||
# 四、Paddle 的稀疏调用体验与稠密的一致性 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这一章叫:Paddle稀疏的设计优势 好一点
|
||
|
||
|
||
# 五、Paddle3D应用实例解读:稀疏 ResNet |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
第三章、第五章的 有些相同内容,标题名和层级有点乱,可以再规划下标题名与标题层级,第四章可以挪到上面去,放到第三章前面:讲API的设计优势
已全部修改,辛苦老师再看看。修改后感觉顺了好多,(^▽^) |
No description provided.