Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
zergtant authored Mar 25, 2019
2 parents 2f60f21 + eedd73d commit 7312c9a
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 95 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ API的改动不是很大,本教程已经通过测试,保证能够在1.0中
[官方1.0说明](https://github.com/pytorch/pytorch/releases/tag/v1.0.0)
[主要改动中文说明](changelog-v1.0.md)

## QQ群
## QQ群 (已升级2000人大群)
群号:985896536

扫描二维码

![QR](PyTorch-Handbook-QR.png)
![QR](PyTorch-Handbook-QR.png)


Expand Down
24 changes: 12 additions & 12 deletions chapter2/2.1.4-pytorch-basics-data-lorder.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
{
"data": {
"text/plain": [
"'1.0.0'"
"'1.0.1.post2'"
]
},
"execution_count": 1,
Expand All @@ -39,7 +39,7 @@
"## Dataset\n",
"Dataset是一个抽象类, 为了能够方便的读取,需要将要使用的数据包装为Dataset类。\n",
"自定义的Dataset需要继承它并且实现两个成员方法:\n",
"1. `__getitem__()` 该方法定义每次怎么获取数据\n",
"1. `__getitem__()` 该方法定义用索引(`0` 到 `len(self)`)获取一条数据或一个样本\n",
"2. `__len__()` 该方法返回数据集的总长度\n",
"\n",
"下面我们使用kaggle上的一个竞赛[bluebook for bulldozers](https://www.kaggle.com/c/bluebook-for-bulldozers/data)自定义一个数据集,为了方便介绍,我们使用里面的数据字典来做说明(因为条数少)"
Expand Down Expand Up @@ -75,7 +75,7 @@
" return len(self.df)\n",
" def __getitem__(self, idx):\n",
" '''\n",
" 根据IDX返回一列数据\n",
" 根据 idx 返回一列数据\n",
" '''\n",
" return self.df.iloc[idx].SalePrice"
]
Expand Down Expand Up @@ -120,7 +120,7 @@
}
],
"source": [
"#实现了__len__ 方法所以可以直接使用len获取数据总数\n",
"#实现了 __len__ 方法所以可以直接使用len获取数据总数\n",
"len(ds_demo)"
]
},
Expand All @@ -141,7 +141,7 @@
}
],
"source": [
"#用索引可以直接访问对应的数据\n",
"#用索引可以直接访问对应的数据, 对应 __getitem__ 方法\n",
"ds_demo[0]"
]
},
Expand All @@ -167,7 +167,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"DataLoader返回的是一个迭代器,我们可以使用迭代器分次获取数据"
"DataLoader返回的是一个可迭代对象,我们可以使用迭代器分次获取数据"
]
},
{
Expand All @@ -193,7 +193,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"或者直接使用for循环对其进行遍历"
"常见的用法是使用for循环对其进行遍历"
]
},
{
Expand All @@ -213,7 +213,7 @@
"source": [
"for i, data in enumerate(dl):\n",
" print(i,data)\n",
" #这里只循环一遍\n",
" # 为了节约空间, 这里只循环一遍\n",
" break"
]
},
Expand Down Expand Up @@ -300,7 +300,7 @@
"source": [
"from torchvision import transforms as transforms\n",
"transform = transforms.Compose([\n",
" transforms.RandomCrop(32, padding=4), #先四周填充0,在吧图像随机裁剪成32*32\n",
" transforms.RandomCrop(32, padding=4), #先四周填充0,在把图像随机裁剪成32*32\n",
" transforms.RandomHorizontalFlip(), #图像一半的概率翻转,一半的概率不翻转\n",
" transforms.RandomRotation((-45,45)), #随机旋转\n",
" transforms.ToTensor(),\n",
Expand Down Expand Up @@ -336,9 +336,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "Pytorch for Deeplearning",
"display_name": "Python 3",
"language": "python",
"name": "pytorch"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -350,7 +350,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.7"
"version": "3.6.8"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit 7312c9a

Please sign in to comment.