Skip to content

Commit 5b70d50

Browse files
author
feng.d.gao
committed
update
1 parent aeda50f commit 5b70d50

4 files changed

+110
-6
lines changed

Basic_concept_1_tensor_operations.ipynb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,10 @@
103103
"a = np.array([1, 2, 3])\n",
104104
"t1 = torch.Tensor(a)\n",
105105
"\n",
106-
"# Perferred copy operation\n",
106+
"# Perferred copy operation vs torch.Tensor()\n",
107107
"t2 = torch.tensor(a)\n",
108108
"\n",
109-
"# Perfered share operation\n",
109+
"# Perfered share operation vs torch.from_numpy()\n",
110110
"t3 = torch.as_tensor(a)\n",
111111
"\n",
112112
"t4 = torch.from_numpy(a)\n",
@@ -237,7 +237,7 @@
237237
"cell_type": "markdown",
238238
"metadata": {},
239239
"source": [
240-
"### 1.2 Sequeeze and unsequeeze\n",
240+
"### 1.2 Squeeze and unsequeeze\n",
241241
"- Squeezing a tensor **removes the axes that have a length of one**\n",
242242
"- Unsqueezing a tensor **adds a dimension with a length of one**"
243243
]
@@ -1176,7 +1176,7 @@
11761176
"name": "python",
11771177
"nbconvert_exporter": "python",
11781178
"pygments_lexer": "ipython3",
1179-
"version": "3.6.4"
1179+
"version": "3.6.8"
11801180
}
11811181
},
11821182
"nbformat": 4,

Basic_concept_2_data_preparation.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@
256256
"name": "python",
257257
"nbconvert_exporter": "python",
258258
"pygments_lexer": "ipython3",
259-
"version": "3.6.4"
259+
"version": "3.6.8"
260260
}
261261
},
262262
"nbformat": 4,

Basic_concept_3_model_save_and_load.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@
204204
"name": "python",
205205
"nbconvert_exporter": "python",
206206
"pygments_lexer": "ipython3",
207-
"version": "3.6.4"
207+
"version": "3.6.8"
208208
}
209209
},
210210
"nbformat": 4,

Basic_concept_4_Model.ipynb

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"import torch\n",
10+
"import torch.nn as nn"
11+
]
12+
},
13+
{
14+
"cell_type": "code",
15+
"execution_count": 2,
16+
"metadata": {},
17+
"outputs": [],
18+
"source": [
19+
"class MyModel(nn.Module):\n",
20+
" def __init__(self):\n",
21+
" super(MyModel, self).__init__()\n",
22+
" self.fc = nn.Linear(in_features=3, out_features=2)\n",
23+
" def forward(self, batch_input):\n",
24+
" return self.fc(batch_input)"
25+
]
26+
},
27+
{
28+
"cell_type": "code",
29+
"execution_count": 3,
30+
"metadata": {},
31+
"outputs": [
32+
{
33+
"name": "stdout",
34+
"output_type": "stream",
35+
"text": [
36+
"MyModel(\n",
37+
" (fc): Linear(in_features=3, out_features=2, bias=True)\n",
38+
")\n"
39+
]
40+
}
41+
],
42+
"source": [
43+
"model = MyModel()\n",
44+
"print(model)"
45+
]
46+
},
47+
{
48+
"cell_type": "code",
49+
"execution_count": 6,
50+
"metadata": {},
51+
"outputs": [
52+
{
53+
"name": "stdout",
54+
"output_type": "stream",
55+
"text": [
56+
"tensor([[-0.2901, 0.8468],\n",
57+
" [-0.2635, 0.6138],\n",
58+
" [-0.0937, 0.7620]], grad_fn=<AddmmBackward>)\n"
59+
]
60+
}
61+
],
62+
"source": [
63+
"batch_input = torch.rand(3, 3)\n",
64+
"output = model(batch_input)\n",
65+
"print(output)"
66+
]
67+
},
68+
{
69+
"cell_type": "code",
70+
"execution_count": null,
71+
"metadata": {},
72+
"outputs": [],
73+
"source": []
74+
},
75+
{
76+
"cell_type": "code",
77+
"execution_count": null,
78+
"metadata": {},
79+
"outputs": [],
80+
"source": []
81+
}
82+
],
83+
"metadata": {
84+
"kernelspec": {
85+
"display_name": "Python 3",
86+
"language": "python",
87+
"name": "python3"
88+
},
89+
"language_info": {
90+
"codemirror_mode": {
91+
"name": "ipython",
92+
"version": 3
93+
},
94+
"file_extension": ".py",
95+
"mimetype": "text/x-python",
96+
"name": "python",
97+
"nbconvert_exporter": "python",
98+
"pygments_lexer": "ipython3",
99+
"version": "3.6.8"
100+
}
101+
},
102+
"nbformat": 4,
103+
"nbformat_minor": 2
104+
}

0 commit comments

Comments
 (0)