This commit is contained in:
Patryk Żywica 2024-08-06 11:37:45 +02:00
parent b4ba0f4aaa
commit da2fbceceb
17 changed files with 1718 additions and 340 deletions

View File

@ -1,4 +1,5 @@
ROOT_DIR=/home/wmi/repos/stud-ai ROOT_DIR=/home/wmi/repos/stud-ai
DATA_DIR=/mnt/gpudata1/studai/datasets
JUPYTER_PORT=42065 JUPYTER_PORT=42065
JUPYTER_TOKEN=some_token JUPYTER_TOKEN=some_token
JUPYTER_DIR=/jupyter JUPYTER_DIR=/jupyter

View File

@ -6,11 +6,13 @@ services:
build: build:
context: ./ context: ./
dockerfile: jupyter.Dockerfile dockerfile: jupyter.Dockerfile
shm_size: '2gb'
env_file: ./.env env_file: ./.env
ports: ports:
- ${JUPYTER_PORT}:${JUPYTER_PORT} - ${JUPYTER_PORT}:${JUPYTER_PORT}
volumes: volumes:
- ${ROOT_DIR}:/jupyter - ${ROOT_DIR}:/jupyter
- ${DATA_DIR}:/jupyter/datasets
environment: environment:
- NVIDIA_VISIBLE_DEVICES=all - NVIDIA_VISIBLE_DEVICES=all
command: command:
@ -24,6 +26,8 @@ services:
'--NotebookApp.token=${JUPYTER_TOKEN}' '--NotebookApp.token=${JUPYTER_TOKEN}'
] ]
deploy: deploy:
restart_policy:
condition: any
resources: resources:
reservations: reservations:
devices: devices:

View File

@ -2,7 +2,8 @@ FROM nvidia/cuda:10.2-runtime AS jupyter-base
WORKDIR / WORKDIR /
RUN apt update && apt install -y --no-install-recommends \ RUN apt update && apt install -y --no-install-recommends \
git build-essential \ git build-essential \
python3-dev python3-pip python3-setuptools python3-dev python3-pip python3-setuptools \
imagemagick
RUN pip3 -q install pip --upgrade RUN pip3 -q install pip --upgrade
RUN pip3 install jupyter numpy pandas torch torchvision tensorboardX RUN pip3 install jupyter numpy pandas torch torchvision tensorboardX

View File

@ -27,8 +27,7 @@
"Getting Started\n", "Getting Started\n",
"---------------\n", "---------------\n",
"\n", "\n",
"Tensors\n", "## Tensors\n",
"^^^^^^^\n",
"\n", "\n",
"Tensors are similar to NumPys ndarrays, with the addition being that\n", "Tensors are similar to NumPys ndarrays, with the addition being that\n",
"Tensors can also be used on a GPU to accelerate computing.\n", "Tensors can also be used on a GPU to accelerate computing.\n",
@ -68,18 +67,18 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 3, "execution_count": 26,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"tensor([[-1.7501e-10, 4.5822e-41, -1.7501e-10],\n", "tensor([[6.3417e-36, 0.0000e+00, 6.3419e-36],\n",
" [ 4.5822e-41, -9.8701e-38, 4.5822e-41],\n", " [0.0000e+00, 1.1210e-43, 0.0000e+00],\n",
" [-9.8892e-38, 4.5822e-41, -9.8700e-38],\n", " [1.5695e-43, 0.0000e+00, 0.0000e+00],\n",
" [ 4.5822e-41, -9.8702e-38, 4.5822e-41],\n", " [0.0000e+00, 6.3917e+04, 4.5559e-41],\n",
" [-9.8701e-38, 4.5822e-41, -9.8703e-38]])\n" " [3.1636e+15, 0.0000e+00, 1.8077e-43]])\n"
] ]
} }
], ],
@ -98,18 +97,18 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 4, "execution_count": 22,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"tensor([[0.8525, 0.7922, 0.2553],\n", "tensor([[0.6721, 0.7974, 0.8837],\n",
" [0.2792, 0.6800, 0.7858],\n", " [0.6526, 0.6741, 0.4159],\n",
" [0.4438, 0.6987, 0.0985],\n", " [0.7239, 0.8301, 0.9470],\n",
" [0.7342, 0.1807, 0.5665],\n", " [0.7420, 0.4967, 0.1845],\n",
" [0.0847, 0.8206, 0.6820]])\n" " [0.2672, 0.3700, 0.3739]])\n"
] ]
} }
], ],
@ -128,7 +127,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 5, "execution_count": 23,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -186,7 +185,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 7, "execution_count": 27,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -198,11 +197,11 @@
" [1., 1., 1.],\n", " [1., 1., 1.],\n",
" [1., 1., 1.],\n", " [1., 1., 1.],\n",
" [1., 1., 1.]], dtype=torch.float64)\n", " [1., 1., 1.]], dtype=torch.float64)\n",
"tensor([[ 1.0131, 1.4739, -0.2482],\n", "tensor([[ 1.8133, -2.0788, 0.1688],\n",
" [-1.8965, -1.6178, 0.4807],\n", " [-0.8336, -0.9961, -0.2995],\n",
" [ 0.1839, 0.3258, -0.6664],\n", " [ 1.5661, -0.0205, -0.1414],\n",
" [-0.9516, -1.7041, 1.1624],\n", " [-2.0433, 0.0211, 2.0895],\n",
" [-0.4448, -1.1328, -0.5092]])\n" " [ 0.2971, -0.2518, 0.5030]])\n"
] ]
} }
], ],
@ -245,8 +244,8 @@
"source": [ "source": [
"<div class=\"alert alert-info\"><h4>Note</h4><p>``torch.Size`` is in fact a tuple, so it supports all tuple operations.</p></div>\n", "<div class=\"alert alert-info\"><h4>Note</h4><p>``torch.Size`` is in fact a tuple, so it supports all tuple operations.</p></div>\n",
"\n", "\n",
"Operations\n", "## Operations\n",
"^^^^^^^^^^\n", "\n",
"There are multiple syntaxes for operations. In the following\n", "There are multiple syntaxes for operations. In the following\n",
"example, we will take a look at the addition operation.\n", "example, we will take a look at the addition operation.\n",
"\n", "\n",
@ -256,18 +255,18 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 9, "execution_count": 28,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"tensor([[ 1.6789, 1.8680, -0.0202],\n", "tensor([[ 2.4870, -1.1092, 0.2733],\n",
" [-1.2243, -1.5905, 0.8047],\n", " [-0.5093, -0.1695, 0.1134],\n",
" [ 0.5959, 0.7308, -0.1883],\n", " [ 2.4207, 0.2844, 0.7987],\n",
" [-0.6292, -0.7051, 1.8369],\n", " [-1.3298, 0.4374, 2.0926],\n",
" [-0.0381, -0.2377, -0.1590]])\n" " [ 1.1103, 0.2101, 1.2337]])\n"
] ]
} }
], ],
@ -293,11 +292,11 @@
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"tensor([[ 1.6789, 1.8680, -0.0202],\n", "tensor([[ 0.0166, 1.8655, 0.2933],\n",
" [-1.2243, -1.5905, 0.8047],\n", " [ 3.2162, 0.1241, 0.9112],\n",
" [ 0.5959, 0.7308, -0.1883],\n", " [ 1.4397, 0.8543, 0.4838],\n",
" [-0.6292, -0.7051, 1.8369],\n", " [ 0.6985, 0.5795, 0.2113],\n",
" [-0.0381, -0.2377, -0.1590]])\n" " [ 0.7467, -0.7956, 0.6495]])\n"
] ]
} }
], ],
@ -315,18 +314,18 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 11, "execution_count": 29,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"tensor([[ 1.6789, 1.8680, -0.0202],\n", "tensor([[ 2.4870, -1.1092, 0.2733],\n",
" [-1.2243, -1.5905, 0.8047],\n", " [-0.5093, -0.1695, 0.1134],\n",
" [ 0.5959, 0.7308, -0.1883],\n", " [ 2.4207, 0.2844, 0.7987],\n",
" [-0.6292, -0.7051, 1.8369],\n", " [-1.3298, 0.4374, 2.0926],\n",
" [-0.0381, -0.2377, -0.1590]])\n" " [ 1.1103, 0.2101, 1.2337]])\n"
] ]
} }
], ],
@ -353,11 +352,11 @@
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"tensor([[ 1.6789, 1.8680, -0.0202],\n", "tensor([[ 0.0166, 1.8655, 0.2933],\n",
" [-1.2243, -1.5905, 0.8047],\n", " [ 3.2162, 0.1241, 0.9112],\n",
" [ 0.5959, 0.7308, -0.1883],\n", " [ 1.4397, 0.8543, 0.4838],\n",
" [-0.6292, -0.7051, 1.8369],\n", " [ 0.6985, 0.5795, 0.2113],\n",
" [-0.0381, -0.2377, -0.1590]])\n" " [ 0.7467, -0.7956, 0.6495]])\n"
] ]
} }
], ],
@ -387,7 +386,7 @@
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"tensor([ 1.4739, -1.6178, 0.3258, -1.7041, -1.1328])\n" "tensor([ 1.3796, -0.6919, 0.7494, -0.1942, -1.0191])\n"
] ]
} }
], ],
@ -405,7 +404,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 14, "execution_count": 36,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -441,8 +440,8 @@
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"tensor([-0.8622])\n", "tensor([-0.0506])\n",
"-0.8622472882270813\n" "-0.05061284825205803\n"
] ]
} }
], ],
@ -473,8 +472,8 @@
"locations (if the Torch Tensor is on CPU), and changing one will change\n", "locations (if the Torch Tensor is on CPU), and changing one will change\n",
"the other.\n", "the other.\n",
"\n", "\n",
"Converting a Torch Tensor to a NumPy Array\n", "## Converting a Torch Tensor to a NumPy Array\n",
"^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", "\n",
"\n" "\n"
] ]
}, },
@ -590,37 +589,22 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 20, "execution_count": 37,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"1.7.0\n" "1.7.0\n",
] "tensor([[ 1.3566, 1.3653, 1.4052, -0.1960],\n",
}, " [ 1.6845, 0.8119, 1.1873, -0.4534],\n",
{ " [ 1.6096, -1.4654, 1.7330, 2.0145],\n",
"name": "stderr", " [ 0.6571, 2.4976, 2.0423, 0.8646]], device='cuda:0')\n",
"output_type": "stream", "tensor([[ 1.3566, 1.3653, 1.4052, -0.1960],\n",
"text": [ " [ 1.6845, 0.8119, 1.1873, -0.4534],\n",
"/usr/local/lib/python3.6/dist-packages/torch/cuda/__init__.py:81: UserWarning: \n", " [ 1.6096, -1.4654, 1.7330, 2.0145],\n",
" Found GPU0 GeForce GTX 760 which is of cuda capability 3.0.\n", " [ 0.6571, 2.4976, 2.0423, 0.8646]], dtype=torch.float64)\n"
" PyTorch no longer supports this GPU because it is too old.\n",
" The minimum cuda capability that we support is 3.5.\n",
" \n",
" warnings.warn(old_gpu_warn % (d, name, major, capability[1]))\n"
]
},
{
"ename": "RuntimeError",
"evalue": "CUDA error: no kernel image is available for execution on the device",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mRuntimeError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-20-9fca8bb14c5b>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mtorch\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcuda\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mis_available\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0mdevice\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtorch\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdevice\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"cuda\"\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;31m# a CUDA device object\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 6\u001b[0;31m \u001b[0my\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtorch\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mones_like\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdevice\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mdevice\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;31m# directly create a tensor on GPU\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 7\u001b[0m \u001b[0mx\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mto\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdevice\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;31m# or just use strings ``.to(\"cuda\")``\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 8\u001b[0m \u001b[0mz\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mx\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0my\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mRuntimeError\u001b[0m: CUDA error: no kernel image is available for execution on the device"
] ]
} }
], ],

View File

@ -2,7 +2,7 @@
"cells": [ "cells": [
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 1, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -66,7 +66,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 2, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -83,18 +83,9 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 3, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"name": "stdout",
"output_type": "stream",
"text": [
"tensor([[1., 1.],\n",
" [1., 1.]], requires_grad=True)\n"
]
}
],
"source": [ "source": [
"x = torch.ones(2, 2, requires_grad=True)\n", "x = torch.ones(2, 2, requires_grad=True)\n",
"print(x)" "print(x)"
@ -110,18 +101,9 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 4, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"name": "stdout",
"output_type": "stream",
"text": [
"tensor([[3., 3.],\n",
" [3., 3.]], grad_fn=<AddBackward0>)\n"
]
}
],
"source": [ "source": [
"y = x + 2\n", "y = x + 2\n",
"print(y)" "print(y)"
@ -137,17 +119,9 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 5, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"name": "stdout",
"output_type": "stream",
"text": [
"<AddBackward0 object at 0x7f0d183e5160>\n"
]
}
],
"source": [ "source": [
"print(y.grad_fn)" "print(y.grad_fn)"
] ]
@ -162,18 +136,9 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 6, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"name": "stdout",
"output_type": "stream",
"text": [
"tensor([[27., 27.],\n",
" [27., 27.]], grad_fn=<MulBackward0>) tensor(27., grad_fn=<MeanBackward0>)\n"
]
}
],
"source": [ "source": [
"z = y * y * 3\n", "z = y * y * 3\n",
"out = z.mean()\n", "out = z.mean()\n",
@ -192,19 +157,9 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 7, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"name": "stdout",
"output_type": "stream",
"text": [
"False\n",
"True\n",
"<SumBackward0 object at 0x7f0cc743b438>\n"
]
}
],
"source": [ "source": [
"a = torch.randn(2, 2)\n", "a = torch.randn(2, 2)\n",
"a = ((a * 3) / (a - 1))\n", "a = ((a * 3) / (a - 1))\n",
@ -229,7 +184,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 8, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -247,18 +202,9 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 9, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"name": "stdout",
"output_type": "stream",
"text": [
"tensor([[4.5000, 4.5000],\n",
" [4.5000, 4.5000]])\n"
]
}
],
"source": [ "source": [
"print(x.grad)" "print(x.grad)"
] ]
@ -334,17 +280,9 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 10, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"name": "stdout",
"output_type": "stream",
"text": [
"tensor([1688.6201, -110.9400, 181.5985], grad_fn=<MulBackward0>)\n"
]
}
],
"source": [ "source": [
"x = torch.randn(3, requires_grad=True)\n", "x = torch.randn(3, requires_grad=True)\n",
"\n", "\n",
@ -368,17 +306,9 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 11, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"name": "stdout",
"output_type": "stream",
"text": [
"tensor([1.0240e+02, 1.0240e+03, 1.0240e-01])\n"
]
}
],
"source": [ "source": [
"v = torch.tensor([0.1, 1.0, 0.0001], dtype=torch.float)\n", "v = torch.tensor([0.1, 1.0, 0.0001], dtype=torch.float)\n",
"y.backward(v)\n", "y.backward(v)\n",
@ -398,19 +328,9 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 12, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"name": "stdout",
"output_type": "stream",
"text": [
"True\n",
"True\n",
"False\n"
]
}
],
"source": [ "source": [
"print(x.requires_grad)\n", "print(x.requires_grad)\n",
"print((x ** 2).requires_grad)\n", "print((x ** 2).requires_grad)\n",
@ -430,19 +350,9 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 13, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"name": "stdout",
"output_type": "stream",
"text": [
"True\n",
"False\n",
"tensor(True)\n"
]
}
],
"source": [ "source": [
"print(x.requires_grad)\n", "print(x.requires_grad)\n",
"y = x.detach()\n", "y = x.detach()\n",

View File

@ -166,7 +166,7 @@
"\n", "\n",
"![image-6.png](attachment:image-6.png)\n", "![image-6.png](attachment:image-6.png)\n",
"\n", "\n",
"> LeNet is a convolutional neural network structure proposed by Yann LeCun et al. in **1989**. In general, LeNet refers to lenet-5 and is a simple convolutional neural network. Convolutional neural networks are a kind of feed-forward neural network whose artificial neurons can respond to a part of the surrounding cells in the coverage range and perform well in large-scale image processing. [Wikipedia](https://en.wikipedia.org/wiki/LeNet)\n", "> LeNet is a convolutional neural network structure proposed by Yann LeCun et al. in **1998**. In general, LeNet refers to lenet-5 and is a simple convolutional neural network. Convolutional neural networks are a kind of feed-forward neural network whose artificial neurons can respond to a part of the surrounding cells in the coverage range and perform well in large-scale image processing. [Wikipedia](https://en.wikipedia.org/wiki/LeNet)\n",
"\n", "\n",
"It is a simple feed-forward network. It takes the input, feeds it\n", "It is a simple feed-forward network. It takes the input, feeds it\n",
"through several layers one after the other, and then finally gives the\n", "through several layers one after the other, and then finally gives the\n",
@ -278,7 +278,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 10, "execution_count": 3,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -308,7 +308,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 19, "execution_count": 4,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -349,7 +349,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 20, "execution_count": 5,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -405,7 +405,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 21, "execution_count": 6,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -434,7 +434,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 22, "execution_count": 7,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -463,7 +463,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 23, "execution_count": 8,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -492,15 +492,15 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 27, "execution_count": 9,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"tensor([[-0.0187, -0.0279, -0.0972, -0.0216, 0.0167, 0.2310, -0.1081, -0.0525,\n", "tensor([[-0.0400, -0.0896, 0.0977, 0.0221, 0.0746, 0.0415, 0.0352, -0.1424,\n",
" 0.0611, 0.0367]], grad_fn=<AddmmBackward>)\n" " 0.0262, -0.0233]], grad_fn=<AddmmBackward>)\n"
] ]
} }
], ],
@ -520,7 +520,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 28, "execution_count": 10,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -584,14 +584,14 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 30, "execution_count": 11,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"tensor(0.8534, grad_fn=<MseLossBackward>)\n" "tensor(1.5053, grad_fn=<MseLossBackward>)\n"
] ]
} }
], ],
@ -629,16 +629,16 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 31, "execution_count": 12,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"<MseLossBackward object at 0x7f78386ee438>\n", "<MseLossBackward object at 0x7f18dc4d2518>\n",
"<AddmmBackward object at 0x7f78386ee390>\n", "<AddmmBackward object at 0x7f18dc4d2ef0>\n",
"<AccumulateGrad object at 0x7f78386ee438>\n" "<AccumulateGrad object at 0x7f18dc4d2518>\n"
] ]
} }
], ],
@ -666,7 +666,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 32, "execution_count": 13,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -676,7 +676,7 @@
"conv1.bias.grad before backward\n", "conv1.bias.grad before backward\n",
"tensor([0., 0., 0., 0., 0., 0.])\n", "tensor([0., 0., 0., 0., 0., 0.])\n",
"conv1.bias.grad after backward\n", "conv1.bias.grad after backward\n",
"tensor([ 0.0008, 0.0015, 0.0122, 0.0016, 0.0040, -0.0035])\n" "tensor([ 0.0006, 0.0030, -0.0049, -0.0047, -0.0134, -0.0125])\n"
] ]
} }
], ],
@ -732,9 +732,18 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 34, "execution_count": 14,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"tensor([0., 0., 0., 0., 0., 0.])\n",
"tensor([ 0.0006, 0.0030, -0.0049, -0.0047, -0.0134, -0.0125])\n"
]
}
],
"source": [ "source": [
"import torch.optim as optim\n", "import torch.optim as optim\n",
"\n", "\n",
@ -743,10 +752,12 @@
"\n", "\n",
"# in your training loop:\n", "# in your training loop:\n",
"optimizer.zero_grad() # zero the gradient buffers\n", "optimizer.zero_grad() # zero the gradient buffers\n",
"print(net.conv1.bias.grad)\n",
"output = net(input)\n", "output = net(input)\n",
"loss = criterion(output, target)\n", "loss = criterion(output, target)\n",
"loss.backward()\n", "loss.backward()\n",
"optimizer.step() # Does the update" "optimizer.step() # Does the update\n",
"print(net.conv1.bias.grad)"
] ]
}, },
{ {

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

383
1-intro/6-one_image.ipynb Normal file

File diff suppressed because one or more lines are too long

393
1-intro/7-colours_nn.ipynb Normal file

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,32 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.9"
}
},
"nbformat": 4,
"nbformat_minor": 4
}

BIN
1-intro/cifar_net.pth Normal file

Binary file not shown.

BIN
1-intro/class-col.pkl Normal file

Binary file not shown.

BIN
1-intro/class-shoe.pkl Normal file

Binary file not shown.

Binary file not shown.

BIN
1-intro/nn-state-dict.pth Normal file

Binary file not shown.

BIN
1-intro/nn.pth Normal file

Binary file not shown.