-
Notifications
You must be signed in to change notification settings - Fork 764
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
映射文档 No.240 #5951
Changes from 1 commit
0467168
5b07e26
113e0d7
28648c0
7c5d2e7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
|
@@ -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 为总长度的比例数组时,转写如下: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
```python | ||
# Pytorch 写法 | ||
lengths = [0.3, 0.3, 0.4] | ||
datasets = torch.utils.data.random_split(range(30), | ||
lengths, | ||
generator=<torch._C.Generator object>) | ||
|
||
# Paddle 写法 | ||
lengths = [0.3, 0.3, 0.4] | ||
lengths = [length * datasets.__len__() for length in lengths] | ||
datasets = paddle.io.random_split(dataset, | ||
lengths, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. range(30)和dataset转化参数名不一致,容易引起误解,generator也要保持一致 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
generator=None) | ||
``` |
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文档写的不太直白:
可为子集合长度列表,列表总和为原数组长度。也可为子集合所占比例列表,列表总和为1.0
子集合长度列表,列表总和为原数组长度。
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.
Done.