Skip to content

Commit

Permalink
Update for latest MEAP, PyTorch v1.3.0, p2ch14.
Browse files Browse the repository at this point in the history
  • Loading branch information
elistevens committed Oct 20, 2019
1 parent f5d199c commit c9ad558
Show file tree
Hide file tree
Showing 62 changed files with 9,122 additions and 2,196 deletions.
17 changes: 8 additions & 9 deletions p1ch3/1_tensors.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,6 @@
}
],
"source": [
"points = torch.tensor([[4.0, 1.0], [5.0, 3.0], [2.0, 1.0]])\n",
"second_point = points[1]\n",
"second_point.size()"
]
Expand Down Expand Up @@ -727,9 +726,9 @@
}
],
"source": [
"some_tensor = torch.ones(3, 4, 5)\n",
"some_tensor_t = some_tensor.transpose(0, 2)\n",
"some_tensor.shape"
"some_t = torch.ones(3, 4, 5)\n",
"transpose_t = some_t.transpose(0, 2)\n",
"some_t.shape"
]
},
{
Expand All @@ -749,7 +748,7 @@
}
],
"source": [
"some_tensor_t.shape"
"transpose_t.shape"
]
},
{
Expand All @@ -769,7 +768,7 @@
}
],
"source": [
"some_tensor.stride()"
"some_t.stride()"
]
},
{
Expand All @@ -789,7 +788,7 @@
}
],
"source": [
"some_tensor_t.stride()"
"transpose_t.stride()"
]
},
{
Expand Down Expand Up @@ -1179,7 +1178,7 @@
"source": [
"f = h5py.File('../data/p1ch3/ourpoints.hdf5', 'r')\n",
"dset = f['coords']\n",
"last_points = dset[1:]"
"last_points = dset[-2:]"
]
},
{
Expand All @@ -1188,7 +1187,7 @@
"metadata": {},
"outputs": [],
"source": [
"last_points = torch.from_numpy(dset[1:])\n",
"last_points = torch.from_numpy(dset[-2:])\n",
"f.close()"
]
},
Expand Down
2 changes: 1 addition & 1 deletion p1ch4/2_time_series_bikes.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
"source": [
"weather_onehot.scatter_(\n",
" dim=1, \n",
" index=first_day[:,9].unsqueeze(1) - 1, # <1>\n",
" index=first_day[:,9].unsqueeze(1).long() - 1, # <1>\n",
" value=1.0)"
]
},
Expand Down
16 changes: 8 additions & 8 deletions p1ch4/3_text_jane_austin.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@
}
],
"source": [
"letter_tensor = torch.zeros(len(line), 128) # <1> \n",
"letter_tensor.shape"
"letter_t = torch.zeros(len(line), 128) # <1> \n",
"letter_t.shape"
]
},
{
Expand All @@ -72,7 +72,7 @@
"source": [
"for i, letter in enumerate(line.lower().strip()):\n",
" letter_index = ord(letter) if ord(letter) < 128 else 0 # <1>\n",
" letter_tensor[i][letter_index] = 1"
" letter_t[i][letter_index] = 1"
]
},
{
Expand Down Expand Up @@ -161,13 +161,13 @@
}
],
"source": [
"word_tensor = torch.zeros(len(words_in_line), len(word2index_dict))\n",
"word_t = torch.zeros(len(words_in_line), len(word2index_dict))\n",
"for i, word in enumerate(words_in_line):\n",
" word_index = word2index_dict[word]\n",
" word_tensor[i][word_index] = 1\n",
" word_t[i][word_index] = 1\n",
" print('{:2} {:4} {}'.format(i, word_index, word))\n",
" \n",
"print(word_tensor.shape)\n"
"print(word_t.shape)\n"
]
},
{
Expand All @@ -187,8 +187,8 @@
}
],
"source": [
"word_tensor = word_tensor.unsqueeze(1)\n",
"word_tensor.shape"
"word_t = word_t.unsqueeze(1)\n",
"word_t.shape"
]
},
{
Expand Down
10 changes: 5 additions & 5 deletions p1ch4/4_audio_chirp.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@
],
"source": [
"sp_left = sp_right = sp_arr\n",
"sp_left_tensor = torch.from_numpy(sp_left)\n",
"sp_right_tensor = torch.from_numpy(sp_right)\n",
"sp_left_tensor.shape, sp_right_tensor.shape"
"sp_left_t = torch.from_numpy(sp_left)\n",
"sp_right_t = torch.from_numpy(sp_right)\n",
"sp_left_t.shape, sp_right_t.shape"
]
},
{
Expand Down Expand Up @@ -197,8 +197,8 @@
}
],
"source": [
"sp_tensor = torch.stack((sp_left_tensor, sp_right_tensor), dim=0)\n",
"sp_tensor.shape"
"sp_t = torch.stack((sp_left_t, sp_right_t), dim=0)\n",
"sp_t.shape"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion p1ch4/5_image_dog.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"import os\n",
"\n",
"data_dir = '../data/p1ch4/image-cats/'\n",
"filenames = [name for name in os.listdir(data_dir) if os.path.splitext(name) == '.png']\n",
"filenames = [name for name in os.listdir(data_dir) if os.path.splitext(name)[-1] == '.png']\n",
"for i, filename in enumerate(filenames):\n",
" img_arr = imageio.imread(filename)\n",
" batch[i] = torch.transpose(torch.from_numpy(img_arr), 0, 2)"
Expand Down
4 changes: 2 additions & 2 deletions p1ch6/1_neural_networks.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,10 @@
"source": [
"def training_loop(n_epochs, optimizer, model, loss_fn, t_u_train, t_u_val, t_c_train, t_c_val):\n",
" for epoch in range(1, n_epochs + 1):\n",
" t_p_train = model(t_un_train) # <1>\n",
" t_p_train = model(t_u_train) # <1>\n",
" loss_train = loss_fn(t_p_train, t_c_train)\n",
"\n",
" t_p_val = model(t_un_val) # <1>\n",
" t_p_val = model(t_u_val) # <1>\n",
" loss_val = loss_fn(t_p_val, t_c_val)\n",
" \n",
" optimizer.zero_grad()\n",
Expand Down
2 changes: 1 addition & 1 deletion p1ch7/1_datasets.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
],
"source": [
"from torchvision import datasets\n",
"data_path = '../data-unversioned/p1ch6/''\n",
"data_path = '../data-unversioned/p1ch6/'\n",
"cifar10 = datasets.CIFAR10(data_path, train=True, download=True)\n",
"cifar10_val = datasets.CIFAR10(data_path, train=False, download=True)"
]
Expand Down
396 changes: 328 additions & 68 deletions p1ch8/1_convolution.ipynb

Large diffs are not rendered by default.

Loading

0 comments on commit c9ad558

Please sign in to comment.