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

映射文档 No.240 #5951

Merged
merged 5 commits into from
Jul 5, 2023
Merged
Changes from all 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
@@ -1,4 +1,4 @@
## [ 参数完全一致 ]torch.utils.data.random_split
## [ 参数不一致 ]torch.utils.data.random_split
### [torch.utils.data.random_split](https://pytorch.org/docs/1.13/data.html?highlight=torch+utils+data+random_split#torch.utils.data.random_split)

```python
Expand All @@ -15,10 +15,27 @@ paddle.io.random_split(dataset,
generator=None)
```

两者参数和用法完全一致,具体如下:
### 参数映射
| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ------------------------------------------------------ |
| dataset | dataset | 表示可迭代数据集。 |
| lengths | lengths | 总和为原数组长度的,子集合长度数组。 |
| generator | generator | 指定采样 data_source 的采样器。默认值为 None。 |
两者参数除 lengths 外用法一致,具体如下:
### 参数差异
| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ |---------------------------------------------------------------------|
| dataset | dataset | 表示可迭代数据集。 |
| lengths | lengths | PyTorch:可为子集合长度列表,列表总和为原数组长度。也可为子集合所占比例列表,列表总和为 1.0。PaddlePaddle: 子集合长度列表,列表总和为原数组长度 |
| generator | generator | 指定采样 data_source 的采样器。默认值为 None。 |

### 转写示例
#### lenghts: 子集合长度列表
```python
# Pytorch 写法
lengths = [0.3, 0.3, 0.4]
datasets = torch.utils.data.random_split(dataset,
lengths,
generator=torch.manual_seed(0))

# Paddle 写法
lengths = [0.3, 0.3, 0.4]
lengths = [length * len(dataset) for length in lengths]
datasets = paddle.io.random_split(dataset,
lengths,
Copy link
Contributor

Choose a reason for hiding this comment

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

range(30)和dataset转化参数名不一致,容易引起误解,generator也要保持一致

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

generator=paddle.seed(0))
```