Skip to content
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

【Hackathon 7th No.36】为 Paddle 代码转换工具新增 API 转换规则(第 3 组) -part #6879

Merged
merged 13 commits into from
Sep 29, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
## [ torch 参数更多 ]torch.signal.windows.blackman
### [torch.signal.windows.blackman](https://pytorch.org/docs/stable/generated/torch.signal.windows.blackman.html)

```python
torch.signal.windows.blackman(M, *, sym=True, dtype=None, layout=torch.strided, device=None, requires_grad=False)
```

### [paddle.audio.functional.get_window](https://www.paddlepaddle.org.cn/documentation/docs/zh/2.6/api/paddle/audio/functional/get_window_cn.html#get-window)

```python
paddle.audio.functional.get_window(window, win_length, fftbins=True, dtype='float64')
enkilee marked this conversation as resolved.
Show resolved Hide resolved
```

PyTorch 相比 Paddle 支持更多其他参数,具体如下:
### 参数映射

| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ------------------------------------------------------ |
| - | window | 窗函数类型,Pytorch 无此参数,Paddle 需设置为 `blackman`。 |
| M | win_length | 输入窗口的长度,也是采样点数。 |
enkilee marked this conversation as resolved.
Show resolved Hide resolved
| sym | fftbins | 判断是否返回适用于过滤器设计的对称窗口。 |
enkilee marked this conversation as resolved.
Show resolved Hide resolved
| dtype | dtype | 返回 Tensor 的数据类型。 |
| layout | -| 表示布局方式, Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 |
| device | - | 表示 Tensor 存放设备位置,Paddle 无此参数,需要转写。 |
| requires_grad | - | 表示是否计算梯度, Paddle 无此参数,需要转写。 |

### 转写示例

#### window:窗函数类型
```python
# PyTorch 写法
torch.signal.windows.blackman(5)

# Paddle 写法
paddle.audio.functional.get_window('blackman', 5)
```

#### requires_grad:是否需要求反向梯度,需要修改该 Tensor 的 stop_gradient 属性
```python
# PyTorch 写法
torch.signal.windows.blackman(5, requires_grad=True)

# Paddle 写法
x = paddle.audio.functional.get_window('blackman', 5)
x.stop_gradient = False
```

#### device: Tensor 的设备
```python
# PyTorch 写法
torch.signal.windows.blackman(5, device=torch.device('cpu'))

# Paddle 写法
y = paddle.audio.functional.window._blackman(5)
enkilee marked this conversation as resolved.
Show resolved Hide resolved
y.cpu()
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
## [ torch 参数更多 ]torch.signal.windows.cosine
### [torch.signal.windows.cosine](https://pytorch.org/docs/stable/generated/torch.signal.windows.cosine.html)

```python
torch.signal.windows.cosine(M, *, sym=True, dtype=None, layout=torch.strided, device=None, requires_grad=False)
```

### [paddle.audio.functional.get_window](https://www.paddlepaddle.org.cn/documentation/docs/zh/2.6/api/paddle/audio/functional/get_window_cn.html#get-window)

```python
paddle.audio.functional.get_window(window, win_length, fftbins=True, dtype='float64')
```

PyTorch 相比 Paddle 支持更多其他参数,具体如下:
### 参数映射

| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ------------------------------------------------------ |
| - | window | 窗函数类型,Pytorch 无此参数,Paddle 需设置为 `cosine`。 |
| M | win_length | 输入窗口的长度,也是采样点数。 |
enkilee marked this conversation as resolved.
Show resolved Hide resolved
| sym | fftbins | 判断是否返回适用于过滤器设计的对称窗口。 |
enkilee marked this conversation as resolved.
Show resolved Hide resolved
| dtype | dtype | 返回 Tensor 的数据类型。 |
| layout | -| 表示布局方式, Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 |
| device | - | 表示 Tensor 存放设备位置,Paddle 无此参数,需要转写。 |
| requires_grad | - | 表示是否计算梯度, Paddle 无此参数,需要转写。 |

### 转写示例

#### window:窗函数类型
```python
# PyTorch 写法
torch.signal.windows.cosine(5)

# Paddle 写法
paddle.audio.functional.get_window('cosine', 5)
```

#### requires_grad:是否需要求反向梯度,需要修改该 Tensor 的 stop_gradient 属性
```python
# PyTorch 写法
torch.signal.windows.cosine(5, requires_grad=True)

# Paddle 写法
x = paddle.audio.functional.get_window('cosine', 5)
x.stop_gradient = False
```

#### device: Tensor 的设备
```python
# PyTorch 写法
torch.signal.windows.cosine(5, device=torch.device('cpu'))

# Paddle 写法
y = paddle.audio.functional.get_window('cosine', 5)
y.cpu()
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
## [ torch 参数更多 ]torch.signal.windows.exponential
### [torch.signal.windows.exponential](https://pytorch.org/docs/stable/generated/torch.signal.windows.exponential.html)

```python
torch.signal.windows.exponential(M, *, center=None, tau=1.0, sym=True, dtype=None, layout=torch.strided, device=None, requires_grad=False)
```

### [paddle.audio.functional.get_window](https://www.paddlepaddle.org.cn/documentation/docs/zh/2.6/api/paddle/audio/functional/get_window_cn.html#get-window)

```python
paddle.audio.functional.get_window(window, win_length, fftbins=True, dtype='float64')
```

PyTorch 相比 Paddle 支持更多其他参数,具体如下:
### 参数映射

| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ------------------------------------------------------ |
| - | window | 窗函数类型,Pytorch 无此参数,Paddle 需设置为 `exponential`。 |
| M | win_length | 输入窗口的长度,也是采样点数。 |
enkilee marked this conversation as resolved.
Show resolved Hide resolved
| sym | fftbins | 判断是否返回适用于过滤器设计的对称窗口。 |
enkilee marked this conversation as resolved.
Show resolved Hide resolved
| center | - | 窗口的中心位置,Paddle 无此参数,暂无转写方式。 |
| tau | - | 窗口的半衰期,Paddle 无此参数,暂无转写方式。 |
| dtype | dtype | 返回 Tensor 的数据类型。 |
| layout | - | 表示布局方式, Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 |
| device | - | 表示 Tensor 存放设备位置,Paddle 无此参数,需要转写。 |
| requires_grad | - | 表示是否计算梯度, Paddle 无此参数,需要转写。 |

### 转写示例

#### window:窗函数类型
```python
# PyTorch 写法
torch.signal.windows.exponential(10)

# Paddle 写法
paddle.audio.functional.get_window('exponential', 10)
```

#### requires_grad:是否需要求反向梯度,需要修改该 Tensor 的 stop_gradient 属性
```python
# PyTorch 写法
torch.signal.windows.exponential(10, requires_grad=True)

# Paddle 写法
x = paddle.audio.functional.get_window('exponential', 10)
x.stop_gradient = False
```

#### device: Tensor 的设备
```python
# PyTorch 写法
torch.signal.windows.exponential(10, device=torch.device('cpu'))

# Paddle 写法
y = paddle.audio.functional.get_window('exponential', 10)
y.cpu()
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
## [ torch 参数更多 ]torch.signal.windows.gaussian
### [torch.signal.windows.gaussian](https://pytorch.org/docs/stable/generated/torch.signal.windows.gaussian.html)

```python
torch.signal.windows.gaussian(M, *, std=1.0, sym=True, dtype=None, layout=torch.strided, device=None, requires_grad=False)
```

### [paddle.audio.functional.get_window](https://www.paddlepaddle.org.cn/documentation/docs/zh/2.6/api/paddle/audio/functional/get_window_cn.html#get-window)

```python
paddle.audio.functional.get_window(window, win_length, fftbins=True, dtype='float64')
```

PyTorch 相比 Paddle 支持更多其他参数,具体如下:
### 参数映射

| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ------------------------------------------------------ |
| - | window | 窗函数类型,Pytorch 无此参数,Paddle 需设置为 `gaussian`。 |
| M | win_length | 输入窗口的长度,也是采样点数。 |
enkilee marked this conversation as resolved.
Show resolved Hide resolved
| std | - | 高斯的标准差,Pytorch 默认值为 1.0, Paddle 无此参数,需要转写。 |
| sym | fftbins | 判断是否返回适用于过滤器设计的对称窗口。 |
enkilee marked this conversation as resolved.
Show resolved Hide resolved
| dtype | dtype | 返回 Tensor 的数据类型。 |
| layout | -| 表示布局方式, Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 |
| device | - | 表示 Tensor 存放设备位置,Paddle 无此参数,需要转写。 |
| requires_grad | - | 表示是否计算梯度, Paddle 无此参数,需要转写。 |

### 转写示例

#### window:窗函数类型
```python
# PyTorch 写法
torch.signal.windows.gaussian(10)

# Paddle 写法
paddle.audio.functional.get_window(('gaussian', 1.0), 10)
```

#### std:高斯的标准差
```python
# PyTorch 写法
torch.signal.windows.gaussian(10, std=2.0)

# Paddle 写法
paddle.audio.functional.get_window(('gaussian', 2.0), 10)
```

#### requires_grad:是否需要求反向梯度,需要修改该 Tensor 的 stop_gradient 属性
```python
# PyTorch 写法
torch.signal.windows.gaussian(10, requires_grad=True)

# Paddle 写法
x = paddle.audio.functional.get_window(('gaussian', 1.0), 10)
x.stop_gradient = False
```

#### device: Tensor 的设备
```python
# PyTorch 写法
torch.signal.windows.gaussian(10, device=torch.device('cpu'))

# Paddle 写法
y = paddle.audio.functional.get_window(('gaussian', 1.0), 10)
y.cpu()
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
## [ torch 参数更多 ]torch.signal.windows.general_cosine
### [torch.signal.windows.general_cosine](https://pytorch.org/docs/stable/generated/torch.signal.windows.general_cosine.html)

```python
torch.signal.windows.general_cosine(M, *, a, sym=True, dtype=None, layout=torch.strided, device=None, requires_grad=False)
```

### [paddle.audio.functional.get_window](https://www.paddlepaddle.org.cn/documentation/docs/zh/2.6/api/paddle/audio/functional/get_window_cn.html#get-window)

```python
paddle.audio.functional.get_window(window, win_length, fftbins=True, dtype='float64')
```

PyTorch 相比 Paddle 支持更多其他参数,具体如下:
### 参数映射

| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ------------------------------------------------------ |
| - | window | 窗函数类型,Pytorch 无此参数,Paddle 需设置为 `general_cosine`。 |
| M | win_length | 输入窗口的长度,也是采样点数。 |
enkilee marked this conversation as resolved.
Show resolved Hide resolved
| a | - | 与每个余弦函数相关的系数。Paddle 无此参数,需要转写。|
| sym | fftbins | 判断是否返回适用于过滤器设计的对称窗口。 |
enkilee marked this conversation as resolved.
Show resolved Hide resolved
| dtype | dtype | 返回 Tensor 的数据类型。 |
| layout | - | 表示布局方式, Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 |
| device | - | 表示 Tensor 存放设备位置,Paddle 无此参数,需要转写。 |
| requires_grad | - | 表示是否计算梯度, Paddle 无此参数,需要转写。 |

### 转写示例

#### window:窗函数类型
```python
# PyTorch 写法
torch.signal.windows.general_cosine(10, a=[0.46, 0.23, 0.31])

# Paddle 写法
paddle.audio.functional.get_window(('general_cosine', [0.46, 0.23, 0.31]), 10)
```

#### a:余弦函数相关的系数
```python
# PyTorch 写法
torch.signal.windows.general_cosine(10, a=[0.1, 0.2, 0.3])

# Paddle 写法
paddle.audio.functional.get_window(('general_cosine', [0.1, 0.2, 0.3]), 10)
```

#### requires_grad:是否需要求反向梯度,需要修改该 Tensor 的 stop_gradient 属性
```python
# PyTorch 写法
torch.signal.windows.general_cosine(10, a=[0.46, 0.23, 0.31], requires_grad=True)

# Paddle 写法
x = paddle.audio.functional.get_window(('general_cosine', [0.46, 0.23, 0.31]), 10)
x.stop_gradient = False
```

#### device: Tensor 的设备
```python
# PyTorch 写法
torch.signal.windows.general_cosine(10, a=[0.46, 0.23, 0.31], device=torch.device('cpu'))

# Paddle 写法
y = paddle.audio.functional.get_window(('general_cosine', [0.46, 0.23, 0.31]), 10)
y.cpu()
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
## [ torch 参数更多 ]torch.signal.windows.general_hamming
### [torch.signal.windows.general_hamming](https://pytorch.org/docs/stable/generated/torch.signal.windows.general_hamming.html)

```python
torch.signal.windows.general_hamming(M, *, alpha=0.54, sym=True, dtype=None, layout=torch.strided, device=None, requires_grad=False)
```

### [paddle.audio.functional.get_window](https://www.paddlepaddle.org.cn/documentation/docs/zh/2.6/api/paddle/audio/functional/get_window_cn.html#get-window)

```python
paddle.audio.functional.get_window(window, win_length, fftbins=True, dtype='float64')
```

PyTorch 相比 Paddle 支持更多其他参数,具体如下:
### 参数映射

| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ------------------------------------------------------ |
| - | window | 窗函数类型,Pytorch 无此参数,Paddle 需设置为 `general_hamming`。 |
| M | win_length | 输入窗口的长度,也是采样点数。 |
enkilee marked this conversation as resolved.
Show resolved Hide resolved
| alpha | - | 窗口系数,Pytorch 默认值为 0.54, Paddle 无默认值,需要转写。|
| sym | fftbins | 判断是否返回适用于过滤器设计的对称窗口。 |
enkilee marked this conversation as resolved.
Show resolved Hide resolved
| dtype | dtype | 返回 Tensor 的数据类型。 |
| layout | - | 表示布局方式, Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 |
| device | - | 表示 Tensor 存放设备位置,Paddle 无此参数,需要转写。 |
| requires_grad | - | 表示是否计算梯度, Paddle 无此参数,需要转写。 |

### 转写示例

#### window:窗函数类型
```python
# PyTorch 写法
torch.signal.windows.general_hamming(10)

# Paddle 写法
paddle.audio.functional.get_window(('general_hamming', 0.54), 10)
```

#### alpha:窗口系数
```python
# PyTorch 写法
torch.signal.windows.general_hamming(10, alpha = 0.6)

# Paddle 写法
paddle.audio.functional.get_window(('general_hamming', 0.6), 10)
```

#### requires_grad:是否需要求反向梯度,需要修改该 Tensor 的 stop_gradient 属性
```python
# PyTorch 写法
torch.signal.windows.general_hamming(10, requires_grad=True)

# Paddle 写法
x = paddle.audio.functional.get_window(('general_hamming', 0.54), 10)
x.stop_gradient = False
```

#### device: Tensor 的设备
```python
# PyTorch 写法
torch.signal.windows.general_hamming(10, device=torch.device('cpu'))

# Paddle 写法
y = paddle.audio.functional.get_window(('general_hamming', 0.54), 10)
y.cpu()
```
Loading