- PyTorch 教程
- PyTorch - 首頁
- PyTorch - 介紹
- PyTorch - 安裝
- 神經網路的數學構建模組
- PyTorch - 神經網路基礎知識
- 機器學習的通用工作流程
- 機器學習 vs. 深度學習
- 實現第一個神經網路
- 神經網路到功能塊
- PyTorch - 術語
- PyTorch - 載入資料
- PyTorch - 線性迴歸
- PyTorch - 卷積神經網路
- PyTorch - 迴圈神經網路
- PyTorch - 資料集
- PyTorch - Convents 簡介
- 從頭開始訓練一個 Convent
- PyTorch - Convent 中的特徵提取
- PyTorch - Convent 的視覺化
- 使用 Convent 進行序列處理
- PyTorch - 詞嵌入
- PyTorch - 遞迴神經網路
- PyTorch 有用的資源
- PyTorch - 快速指南
- PyTorch - 有用的資源
- PyTorch - 討論
PyTorch - 資料集
在本章中,我們將重點討論 torchvision.datasets 及其各種型別。PyTorch 包含以下資料集載入器 -
- MNIST
- COCO(字幕和檢測)
資料集主要包含以下兩種型別的函式 -
變換 - 一個函式,接收一張影像並返回標準內容的修改版本。這些內容可以與變換結合在一起。
目標變換 - 一個函式,接收目標並將其變換。例如,接收字幕字串並返回文字索引的張量。
MNIST
以下是 MNIST 資料集的示例程式碼 -
dset.MNIST(root, train = TRUE, transform = NONE, target_transform = None, download = FALSE)
引數如下 -
root - 已處理資料所在的資料集的根目錄。
train - True = 訓練集,False = 測試集
download - True = 從網際網路下載資料集並將其放入根目錄。
COCO
這需要安裝 COCO API。以下示例用於演示使用 PyTorch 實現 COCO 資料集 -
import torchvision.dataset as dset import torchvision.transforms as transforms cap = dset.CocoCaptions(root = ‘ dir where images are’, annFile = ’json annotation file’, transform = transforms.ToTensor()) print(‘Number of samples: ‘, len(cap)) print(target)
獲得的輸出如下 -
Number of samples: 82783 Image Size: (3L, 427L, 640L)
廣告