Skip to content

Conversation

lightrain-a
Copy link
Contributor

No description provided.

Copy link

paddle-bot bot commented Apr 26, 2024

你的PR提交成功,感谢你对开源项目的贡献!
请检查PR提交格式和内容是否完备,具体请参考示例模版
Your PR has been submitted. Thanks for your contribution!
Please check its format and content. For this, you can refer to Template and Demo.


PaddlePaddle 提供了完整的支持来创建和操作 COO 和 CSR 格式的稀疏张量。以下是使用 PaddlePaddle 创建和操作这些张量的具体方法。

![在这里插入图片描述](https://img-blog.csdnimg.cn/direct/6a79578e9fbb4f98b5cc4e83cac580ff.png)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的图片有吗

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

上传啦,辛苦老师再看看

Copy link
Contributor

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` 则描述了张量的维度。

![image](https://github.com/lightrain-a/community/assets/164860023/6ea1fbe9-9b9b-4b01-b60d-a474103212db)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这种形式可以正常预览吗,一般是把图片也需要提交过来,看一下其他的写法

Copy link
Contributor Author

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` 则直接存储这些非零元素的值。

![在这里插入图片描述](https://img-blog.csdnimg.cn/direct/c5b958755ace496d95409f2ec00eb3ae.png)
Copy link
Contributor

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. **转换功能**:
Copy link
Contributor

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 创建和操作这些张量的具体方法。

![在这里插入图片描述](https://img-blog.csdnimg.cn/direct/6a79578e9fbb4f98b5cc4e83cac580ff.png)
Copy link
Contributor

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)**:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个不是共通参数吧,下面的特定参数也进行了描述的

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已调整到后面

- 这些层专为稀疏数据优化,减少了对零值的计算和存储,从而提高了性能和效率。

2. **批归一化层**:
- `BatchNorm3D`: 用于3D数据的批归一化层,支持与稀疏卷积层配合使用。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

写一下API的全名吧

Copy link
Contributor Author

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. **稀疏卷积层**:
Copy link
Contributor

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`,支持在稀疏数据路径中使用,与常规的激活函数使用方法相同。
Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

model没有实例化

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已完善补充

```
输出:

![在这里插入图片描述](https://img-blog.csdnimg.cn/direct/9b6669da0c6f4a28bd3b7f768c62edf8.png)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

图片写法更正

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的图片是代码输出结果截图,学习图片写法的过程中,发现都是放的为文字版运行结果,已将结果文字复制进来

@lightrain-a
Copy link
Contributor Author

已全部修改,辛苦老师再看看


2. **CSR格式(Compressed Sparse Row)**:
- 这是另一种常用的稀疏表示格式,主要用于优化行访问的性能,其中非零元素通过行的压缩方式进行存储。
- 使用 `paddle.sparse.sparse_csr_tensor(crow_indices, col_indices, values, shape)` 可以创建 CSR 格式的稀疏张量,其中 `crow_indices` 是一个一维整数张量,指示每一行的起始非零元素在 `values` 中的位置;`col_indices` 是一个一维整数张量,指示每个非零元素的列索引;`values` 是一个张量,包含所有非零元素的值;`shape` 是一个定义张量形状的整数列表或张量。
Copy link
Contributor

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. **转换功能**:
Copy link
Contributor

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 格式**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这一段应该不需要了,和上面是重复内容

# 二、Paddle稀疏张量支持


PaddlePaddle 支持多种类型的稀疏张量,主要包括:
Copy link
Contributor

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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个采用 省略号 把下面的values精简下吧




# 四、Paddle 的稀疏调用体验与稠密的一致性
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这一章叫:Paddle稀疏的设计优势 好一点




# 五、Paddle3D应用实例解读:稀疏 ResNet
Copy link
Contributor

@zhwesky2010 zhwesky2010 May 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

第三章、第五章的 有些相同内容,标题名和层级有点乱,可以再规划下标题名与标题层级,第四章可以挪到上面去,放到第三章前面:讲API的设计优势

@lightrain-a
Copy link
Contributor Author

已全部修改,辛苦老师再看看。修改后感觉顺了好多,(^▽^)

@zhwesky2010 zhwesky2010 merged commit a96f3ce into PaddlePaddle:master May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants