Browse Source

Add references

pull/10/head
bushuhui 3 years ago
parent
commit
29b4a79e86
7 changed files with 75 additions and 30 deletions
  1. +1
    -0
      5_nn/3-softmax_ce.ipynb
  2. +19
    -7
      6_pytorch/1-tensor.ipynb
  3. +17
    -7
      6_pytorch/2-autograd.ipynb
  4. +29
    -11
      6_pytorch/3-linear-regression.ipynb
  5. +8
    -4
      6_pytorch/optimizer/6_6-adam.ipynb
  6. +1
    -1
      7_deep_learning/1_CNN/2-vgg.ipynb
  7. BIN
      7_deep_learning/1_CNN/CNN_Introduction.pptx

+ 1
- 0
5_nn/3-softmax_ce.ipynb View File

@@ -263,6 +263,7 @@
"## 参考资料\n",
"\n",
"* [一文详解Softmax函数](https://zhuanlan.zhihu.com/p/105722023)\n",
"* [损失函数:交叉熵详解](https://zhuanlan.zhihu.com/p/115277553)\n",
"* [交叉熵代价函数(作用及公式推导)](https://blog.csdn.net/u014313009/article/details/51043064)\n",
"* [手打例子一步一步带你看懂softmax函数以及相关求导过程](https://www.jianshu.com/p/ffa51250ba2e)\n",
"* [简单易懂的softmax交叉熵损失函数求导](https://www.jianshu.com/p/c02a1fbffad6)"


+ 19
- 7
6_pytorch/1-tensor.ipynb View File

@@ -42,7 +42,9 @@
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import torch\n",
@@ -52,7 +54,9 @@
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# 创建一个 numpy ndarray\n",
@@ -69,7 +73,9 @@
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"pytorch_tensor1 = torch.tensor(numpy_tensor)\n",
@@ -100,7 +106,9 @@
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# 如果 pytorch tensor 在 cpu 上\n",
@@ -129,7 +137,9 @@
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# 第一种方式是定义 cuda 数据类型\n",
@@ -160,7 +170,9 @@
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"cpu_tensor = gpu_tensor.cpu()"
@@ -716,7 +728,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.9"
"version": "3.5.4"
}
},
"nbformat": 4,


+ 17
- 7
6_pytorch/2-autograd.ipynb View File

@@ -119,7 +119,9 @@
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"z = torch.mean(torch.matmul(w, x) + b) # torch.matmul 是做矩阵乘法\n",
@@ -275,7 +277,9 @@
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"n.backward(torch.ones_like(n)) # 将 (w0, w1) 取成 (1, 1)"
@@ -349,7 +353,9 @@
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"y.backward(retain_graph=True) # 设置 retain_graph 为 True 来保留计算图"
@@ -375,7 +381,9 @@
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"y.backward() # 再做一次自动求导,这次不保留计算图"
@@ -455,7 +463,9 @@
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"x = torch.tensor([2, 3], dtype=torch.float, requires_grad=True)\n",
@@ -553,7 +563,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
@@ -567,7 +577,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
"version": "3.5.4"
}
},
"nbformat": 4,


+ 29
- 11
6_pytorch/3-linear-regression.ipynb View File

@@ -151,7 +151,9 @@
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# 转换成 Tensor\n",
@@ -166,7 +168,9 @@
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# 构建线性回归模型\n",
@@ -180,7 +184,9 @@
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"y_ = linear_model(x_train)"
@@ -275,7 +281,9 @@
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# 自动求导\n",
@@ -305,7 +313,9 @@
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# 更新一次参数\n",
@@ -542,7 +552,9 @@
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# 构建数据 x 和 y\n",
@@ -582,7 +594,9 @@
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# 定义参数\n",
@@ -670,7 +684,9 @@
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# 自动求导\n",
@@ -702,7 +718,9 @@
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# 更新一下参数\n",
@@ -853,7 +871,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
@@ -867,7 +885,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
"version": "3.5.4"
}
},
"nbformat": 4,


+ 8
- 4
6_pytorch/optimizer/6_6-adam.ipynb View File

@@ -47,7 +47,9 @@
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def adam(parameters, vs, sqrs, lr, t, beta1=0.9, beta2=0.999):\n",
@@ -63,7 +65,9 @@
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import numpy as np\n",
@@ -267,7 +271,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
@@ -281,7 +285,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
"version": "3.5.4"
}
},
"nbformat": 4,


+ 1
- 1
7_deep_learning/1_CNN/2-vgg.ipynb View File

@@ -462,7 +462,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.9"
"version": "3.5.4"
}
},
"nbformat": 4,


BIN
7_deep_learning/1_CNN/CNN_Introduction.pptx View File


Loading…
Cancel
Save