pytorch dataset
时间: 2023-08-31 09:08:20 浏览: 135
在PyTorch中,Dataset是一个抽象类,需要作为父类被继承。torchvision中的datasets都是torch.utils.data.Dataset的子类,它们实现了__getitem__和__len__方法,因此可以用torch.utils.data.DataLoader进行数据加载。你可以使用官方提供的数据集,也可以自定义自己的数据集。
下面是一个自定义的数据集的示例代码:
```python
from torch.utils.data import Dataset
import torch
import numpy as np
class DiabetesDataset(Dataset):
def __init__(self, filePath):
xy = np.loadtxt(filePath, delimiter=',', dtype=np.float32)
self.len = xy.shape<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *3* [pytorch的dataset用法详解](https://blog.csdn.net/EMIvv/article/details/122509392)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"]
- *2* [Pytorch实现Dataset数据集导入 必要性解释及代码实操](https://blog.csdn.net/weixin_43920520/article/details/127482167)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文