Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 39 additions & 26 deletions tutorial-contents-notebooks/303_build_nn_quickly.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,19 @@
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"import torch\n",
"import torch.nn.functional as F"
"import torch.nn.functional as F\n",
"from collections import OrderedDict"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"# replace following class code with an easy sequential network\n",
Expand All @@ -49,20 +46,16 @@
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"net1 = Net(1, 10, 1)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": true
},
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"# easy and fast way to build your network\n",
Expand All @@ -75,28 +68,48 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"# network with specific layer names\n",
"net3 = torch.nn.Sequential(OrderedDict([\n",
" ('fc1', torch.nn.Linear(1, 10)),\n",
" ('relu', torch.nn.ReLU()),\n",
" ('output', torch.nn.Linear(10, 1))\n",
"]))"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Net (\n",
" (hidden): Linear (1 -> 10)\n",
" (predict): Linear (10 -> 1)\n",
"Net(\n",
" (hidden): Linear(in_features=1, out_features=10, bias=True)\n",
" (predict): Linear(in_features=10, out_features=1, bias=True)\n",
")\n",
"Sequential(\n",
" (0): Linear(in_features=1, out_features=10, bias=True)\n",
" (1): ReLU()\n",
" (2): Linear(in_features=10, out_features=1, bias=True)\n",
")\n",
"Sequential (\n",
" (0): Linear (1 -> 10)\n",
" (1): ReLU ()\n",
" (2): Linear (10 -> 1)\n",
"Sequential(\n",
" (fc1): Linear(in_features=1, out_features=10, bias=True)\n",
" (relu): ReLU()\n",
" (output): Linear(in_features=10, out_features=1, bias=True)\n",
")\n"
]
}
],
"source": [
"print(net1) # net1 architecture\n",
"print(net2) # net2 architecture"
"print(net2) # net2 architecture\n",
"print(net3) # net3 architecture"
]
},
{
Expand All @@ -111,7 +124,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -125,7 +138,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.2"
"version": "3.9.7"
}
},
"nbformat": 4,
Expand Down
Loading