From 8570d5da16495de99d2d308521b627c5933f8a6a Mon Sep 17 00:00:00 2001 From: wassname Date: Tue, 13 Oct 2020 05:25:23 +0000 Subject: [PATCH] typos --- .../Intro_to_NN_Part_2.ipynb | 1316 +++++++++++++---- .../Intro_to_NN_Part_2.py | 39 +- 2 files changed, 1099 insertions(+), 256 deletions(-) diff --git a/notebooks/c02_Intro_to_NN_Part_2/Intro_to_NN_Part_2.ipynb b/notebooks/c02_Intro_to_NN_Part_2/Intro_to_NN_Part_2.ipynb index df6a5de..df40b18 100644 --- a/notebooks/c02_Intro_to_NN_Part_2/Intro_to_NN_Part_2.ipynb +++ b/notebooks/c02_Intro_to_NN_Part_2/Intro_to_NN_Part_2.ipynb @@ -2,11 +2,11 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": 51, "metadata": { "ExecuteTime": { - "end_time": "2020-10-03T05:07:29.705076Z", - "start_time": "2020-10-03T05:07:29.343977Z" + "end_time": "2020-10-13T05:12:50.830757Z", + "start_time": "2020-10-13T05:12:50.826831Z" } }, "outputs": [], @@ -15,7 +15,10 @@ "import torch\n", "from torch import optim\n", "from torch import nn\n", - "import torch.nn.functional as F" + "import torch.nn.functional as F\n", + "\n", + "import numpy as np\n", + "from tqdm.auto import tqdm" ] }, { @@ -102,7 +105,7 @@ "
\n", "\n", "**NOTE:**
\n", - "Use `nn.maxpoo2d` in Pytorch for 2d Max Pooling.\n", + "Use `nn.maxpool2d` in Pytorch for 2d Max Pooling.\n", "
\n", "\n", "Another important concept of CNNs is pooling, which is a form of non-linear down-sampling. The example below, shows Max pooling with a 2x2 filter and stride = 2. In every sub-region, the max value obtained.\n", @@ -129,16 +132,18 @@ "\n", "In this notebook, we will be using the landmass dataset, which have been preprocessed already. In this dataset, we have images of 4 different types of landmass: 'Chaotic Horizon', 'Fault', 'Horizon', 'Salt Dome'.\n", "\n", + "This is an example of [seismic data](https://en.wikipedia.org/wiki/Reflection_seismology) which is a way of using seismic to image the structure of the Earth, below the surface. These waves are similar to sounds waves in air. The lines represent changes in density below the surface.\n", + "\n", "We will train a CNN to learn how to classify images into those 4 groups." ] }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 52, "metadata": { "ExecuteTime": { - "end_time": "2020-10-03T05:07:31.498442Z", - "start_time": "2020-10-03T05:07:31.064266Z" + "end_time": "2020-10-13T05:12:52.376404Z", + "start_time": "2020-10-13T05:12:52.297057Z" } }, "outputs": [ @@ -148,11 +153,11 @@ "text": [ "Dataset LandmassF3Patches\n", " Number of datapoints: 13250\n", - " Root location: /Users/capcarde/Desktop/ThreeSpringsContract/Chevron/deep_ml_curriculum/data/processed/landmass-f3\n", + " Root location: /home/wassname/notebooks/deep_ml_curriculum/data/processed/landmass-f3\n", " Split: Train\n", "Dataset LandmassF3Patches\n", " Number of datapoints: 4417\n", - " Root location: /Users/capcarde/Desktop/ThreeSpringsContract/Chevron/deep_ml_curriculum/data/processed/landmass-f3\n", + " Root location: /home/wassname/notebooks/deep_ml_curriculum/data/processed/landmass-f3\n", " Split: Test\n" ] } @@ -174,11 +179,11 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 53, "metadata": { "ExecuteTime": { - "end_time": "2020-10-03T05:07:31.613322Z", - "start_time": "2020-10-03T05:07:31.610029Z" + "end_time": "2020-10-13T05:12:52.455907Z", + "start_time": "2020-10-13T05:12:52.443346Z" } }, "outputs": [ @@ -199,11 +204,11 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 54, "metadata": { "ExecuteTime": { - "end_time": "2020-10-03T05:07:32.986028Z", - "start_time": "2020-10-03T05:07:32.976456Z" + "end_time": "2020-10-13T05:12:52.596824Z", + "start_time": "2020-10-13T05:12:52.587281Z" } }, "outputs": [ @@ -213,7 +218,7 @@ "deep_ml_curriculum.data.landmass_f3.LandmassF3Patches" ] }, - "execution_count": 4, + "execution_count": 54, "metadata": {}, "output_type": "execute_result" } @@ -233,11 +238,11 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 55, "metadata": { "ExecuteTime": { - "end_time": "2020-10-03T05:07:34.203059Z", - "start_time": "2020-10-03T05:07:34.176311Z" + "end_time": "2020-10-13T05:12:52.885552Z", + "start_time": "2020-10-13T05:12:52.880373Z" } }, "outputs": [ @@ -252,10 +257,10 @@ "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAGMAAABjCAAAAACqUOFJAAAfXElEQVR4nC3BWcyl52EQ4Hf73m9fzv6f85/599k9mXFsx+6kTpyQuFnagJpSiYICXIBQQe0NElQIJLhFSFx0AaEWCqWlLW3VJF1om2CnsePYju0Zzz7z79vZz7dv78YNzwP/ZwFFnbdKx2mYESeiyHyJFyTy6mG5XBRaEktucZyCKi30aExis9lGCpvnAa0ND7lsDkvWYBiQdlKqSWUyPhsiISI/FLStxrai5C4CgsNj5bOOf7qSJKDmRZwDHZVXQ1VHdOInkWwiJBoFoUPfMx1XnWdlJIDlYKJmQriKuIYsNQZl3VCKZroOsG/hQY19APsgg1/TIr3hnegoZhj6U2Si8yoKSEMSEyIDIuEU9Tyw2gZMeDEMIM7hUYFDpLsZ1WpcKUtyxq2acKzlxgBRo7bHhtYocCsUelH46Bz+fZUx25vbGGaJu4ibCs+Mpq/ZGgq9nBCtsXC1UelqtPDLmRpk1QKmuo5BAI+kBRFokFNUxqh2Ks9G0BVOVehMM5WgoOKRdBMNEsPemoV1i9omTxlpWxlZhdfj0JUEiUAmsi6MpEjLyvYNuLUb666Ph+XYi2DcVAAJpnHbJVIoaBg6ndbVuEjLzZguMJhb2lE7n6k+WSiNuJrJWDk3E10jzcZgnp5PndzFkwt8oSZ0GUqb+d0Wkm1srDQA7JXHOY3IqlGmsFZyy2pKYXBPZRXC+ZKmbL2APVC5rrPmy0u1Bf9xVVHfJqhYnHtKJ3av5fF7S1IIkyZe7JDUzQFpsF6jyKXTcbFQ9Um3nVRJjHSUayqvtxIH5pAhNZGuRZmWyILoBq2AI5xp2uQluTGNCAPGUMY7c6sWgc+y/nbaH0GlF/PigqMYdRDPIMtom/PRa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CMAulnJCxhTHWsG3AlbParjxGgJMKTEMflrUXc4QtoQ8PyqI0m3mtmUmC4xYwK7M0bIWw9B2prxRIL1OWkkphrSRWEWIdkbKuIXFh4XsJw1UMoAnqGFXcb4n/B27CcxMNEC4tAAAAAElFTkSuQmCC\n", "text/plain": [ - "" + "" ] }, - "execution_count": 5, + "execution_count": 55, "metadata": {}, "output_type": "execute_result" } @@ -268,11 +273,11 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 56, "metadata": { "ExecuteTime": { - "end_time": "2020-10-03T05:07:38.217428Z", - "start_time": "2020-10-03T05:07:38.213639Z" + "end_time": "2020-10-13T05:12:53.043368Z", + "start_time": "2020-10-13T05:12:53.040218Z" } }, "outputs": [ @@ -282,7 +287,7 @@ "['Chaotic Horizon', 'Fault', 'Horizon', 'Salt Dome']" ] }, - "execution_count": 6, + "execution_count": 56, "metadata": {}, "output_type": "execute_result" } @@ -319,11 +324,716 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 57, "metadata": { "ExecuteTime": { - "end_time": "2020-10-03T05:07:41.733429Z", - "start_time": "2020-10-03T05:07:41.725557Z" + "end_time": "2020-10-13T05:12:53.337917Z", + "start_time": "2020-10-13T05:12:53.330377Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Help on class Conv2d in module torch.nn.modules.conv:\n", + "\n", + "class Conv2d(_ConvNd)\n", + " | Conv2d(in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, groups=1, bias=True, padding_mode='zeros')\n", + " | \n", + " | Applies a 2D convolution over an input signal composed of several input\n", + " | planes.\n", + " | \n", + " | In the simplest case, the output value of the layer with input size\n", + " | :math:`(N, C_{\\text{in}}, H, W)` and output :math:`(N, C_{\\text{out}}, H_{\\text{out}}, W_{\\text{out}})`\n", + " | can be precisely described as:\n", + " | \n", + " | .. math::\n", + " | \\text{out}(N_i, C_{\\text{out}_j}) = \\text{bias}(C_{\\text{out}_j}) +\n", + " | \\sum_{k = 0}^{C_{\\text{in}} - 1} \\text{weight}(C_{\\text{out}_j}, k) \\star \\text{input}(N_i, k)\n", + " | \n", + " | \n", + " | where :math:`\\star` is the valid 2D `cross-correlation`_ operator,\n", + " | :math:`N` is a batch size, :math:`C` denotes a number of channels,\n", + " | :math:`H` is a height of input planes in pixels, and :math:`W` is\n", + " | width in pixels.\n", + " | \n", + " | * :attr:`stride` controls the stride for the cross-correlation, a single\n", + " | number or a tuple.\n", + " | \n", + " | * :attr:`padding` controls the amount of implicit zero-paddings on both\n", + " | sides for :attr:`padding` number of points for each dimension.\n", + " | \n", + " | * :attr:`dilation` controls the spacing between the kernel points; also\n", + " | known as the à trous algorithm. It is harder to describe, but this `link`_\n", + " | has a nice visualization of what :attr:`dilation` does.\n", + " | \n", + " | * :attr:`groups` controls the connections between inputs and outputs.\n", + " | :attr:`in_channels` and :attr:`out_channels` must both be divisible by\n", + " | :attr:`groups`. For example,\n", + " | \n", + " | * At groups=1, all inputs are convolved to all outputs.\n", + " | * At groups=2, the operation becomes equivalent to having two conv\n", + " | layers side by side, each seeing half the input channels,\n", + " | and producing half the output channels, and both subsequently\n", + " | concatenated.\n", + " | * At groups= :attr:`in_channels`, each input channel is convolved with\n", + " | its own set of filters, of size:\n", + " | :math:`\\left\\lfloor\\frac{out\\_channels}{in\\_channels}\\right\\rfloor`.\n", + " | \n", + " | The parameters :attr:`kernel_size`, :attr:`stride`, :attr:`padding`, :attr:`dilation` can either be:\n", + " | \n", + " | - a single ``int`` -- in which case the same value is used for the height and width dimension\n", + " | - a ``tuple`` of two ints -- in which case, the first `int` is used for the height dimension,\n", + " | and the second `int` for the width dimension\n", + " | \n", + " | .. note::\n", + " | \n", + " | Depending of the size of your kernel, several (of the last)\n", + " | columns of the input might be lost, because it is a valid `cross-correlation`_,\n", + " | and not a full `cross-correlation`_.\n", + " | It is up to the user to add proper padding.\n", + " | \n", + " | .. note::\n", + " | \n", + " | When `groups == in_channels` and `out_channels == K * in_channels`,\n", + " | where `K` is a positive integer, this operation is also termed in\n", + " | literature as depthwise convolution.\n", + " | \n", + " | In other words, for an input of size :math:`(N, C_{in}, H_{in}, W_{in})`,\n", + " | a depthwise convolution with a depthwise multiplier `K`, can be constructed by arguments\n", + " | :math:`(in\\_channels=C_{in}, out\\_channels=C_{in} \\times K, ..., groups=C_{in})`.\n", + " | \n", + " | .. include:: cudnn_deterministic.rst\n", + " | \n", + " | Args:\n", + " | in_channels (int): Number of channels in the input image\n", + " | out_channels (int): Number of channels produced by the convolution\n", + " | kernel_size (int or tuple): Size of the convolving kernel\n", + " | stride (int or tuple, optional): Stride of the convolution. Default: 1\n", + " | padding (int or tuple, optional): Zero-padding added to both sides of the input. Default: 0\n", + " | padding_mode (string, optional): ``'zeros'``, ``'reflect'``, ``'replicate'`` or ``'circular'``. Default: ``'zeros'``\n", + " | dilation (int or tuple, optional): Spacing between kernel elements. Default: 1\n", + " | groups (int, optional): Number of blocked connections from input channels to output channels. Default: 1\n", + " | bias (bool, optional): If ``True``, adds a learnable bias to the output. Default: ``True``\n", + " | \n", + " | Shape:\n", + " | - Input: :math:`(N, C_{in}, H_{in}, W_{in})`\n", + " | - Output: :math:`(N, C_{out}, H_{out}, W_{out})` where\n", + " | \n", + " | .. math::\n", + " | H_{out} = \\left\\lfloor\\frac{H_{in} + 2 \\times \\text{padding}[0] - \\text{dilation}[0]\n", + " | \\times (\\text{kernel\\_size}[0] - 1) - 1}{\\text{stride}[0]} + 1\\right\\rfloor\n", + " | \n", + " | .. math::\n", + " | W_{out} = \\left\\lfloor\\frac{W_{in} + 2 \\times \\text{padding}[1] - \\text{dilation}[1]\n", + " | \\times (\\text{kernel\\_size}[1] - 1) - 1}{\\text{stride}[1]} + 1\\right\\rfloor\n", + " | \n", + " | Attributes:\n", + " | weight (Tensor): the learnable weights of the module of shape\n", + " | :math:`(\\text{out\\_channels}, \\frac{\\text{in\\_channels}}{\\text{groups}},`\n", + " | :math:`\\text{kernel\\_size[0]}, \\text{kernel\\_size[1]})`.\n", + " | The values of these weights are sampled from\n", + " | :math:`\\mathcal{U}(-\\sqrt{k}, \\sqrt{k})` where\n", + " | :math:`k = \\frac{groups}{C_\\text{in} * \\prod_{i=0}^{1}\\text{kernel\\_size}[i]}`\n", + " | bias (Tensor): the learnable bias of the module of shape (out_channels). If :attr:`bias` is ``True``,\n", + " | then the values of these weights are\n", + " | sampled from :math:`\\mathcal{U}(-\\sqrt{k}, \\sqrt{k})` where\n", + " | :math:`k = \\frac{groups}{C_\\text{in} * \\prod_{i=0}^{1}\\text{kernel\\_size}[i]}`\n", + " | \n", + " | Examples::\n", + " | \n", + " | >>> # With square kernels and equal stride\n", + " | >>> m = nn.Conv2d(16, 33, 3, stride=2)\n", + " | >>> # non-square kernels and unequal stride and with padding\n", + " | >>> m = nn.Conv2d(16, 33, (3, 5), stride=(2, 1), padding=(4, 2))\n", + " | >>> # non-square kernels and unequal stride and with padding and dilation\n", + " | >>> m = nn.Conv2d(16, 33, (3, 5), stride=(2, 1), padding=(4, 2), dilation=(3, 1))\n", + " | >>> input = torch.randn(20, 16, 50, 100)\n", + " | >>> output = m(input)\n", + " | \n", + " | .. _cross-correlation:\n", + " | https://en.wikipedia.org/wiki/Cross-correlation\n", + " | \n", + " | .. _link:\n", + " | https://github.com/vdumoulin/conv_arithmetic/blob/master/README.md\n", + " | \n", + " | Method resolution order:\n", + " | Conv2d\n", + " | _ConvNd\n", + " | torch.nn.modules.module.Module\n", + " | builtins.object\n", + " | \n", + " | Methods defined here:\n", + " | \n", + " | __init__(self, in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, groups=1, bias=True, padding_mode='zeros')\n", + " | Initializes internal Module state, shared by both nn.Module and ScriptModule.\n", + " | \n", + " | forward(self, input)\n", + " | Defines the computation performed at every call.\n", + " | \n", + " | Should be overridden by all subclasses.\n", + " | \n", + " | .. note::\n", + " | Although the recipe for forward pass needs to be defined within\n", + " | this function, one should call the :class:`Module` instance afterwards\n", + " | instead of this since the former takes care of running the\n", + " | registered hooks while the latter silently ignores them.\n", + " | \n", + " | ----------------------------------------------------------------------\n", + " | Methods inherited from _ConvNd:\n", + " | \n", + " | __setstate__(self, state)\n", + " | \n", + " | extra_repr(self)\n", + " | Set the extra representation of the module\n", + " | \n", + " | To print customized extra information, you should reimplement\n", + " | this method in your own modules. Both single-line and multi-line\n", + " | strings are acceptable.\n", + " | \n", + " | reset_parameters(self)\n", + " | \n", + " | ----------------------------------------------------------------------\n", + " | Data and other attributes inherited from _ConvNd:\n", + " | \n", + " | __annotations__ = {'bias': typing.Union[torch.Tensor, NoneType]}\n", + " | \n", + " | __constants__ = ['stride', 'padding', 'dilation', 'groups', 'padding_m...\n", + " | \n", + " | ----------------------------------------------------------------------\n", + " | Methods inherited from torch.nn.modules.module.Module:\n", + " | \n", + " | __call__(self, *input, **kwargs)\n", + " | Call self as a function.\n", + " | \n", + " | __delattr__(self, name)\n", + " | Implement delattr(self, name).\n", + " | \n", + " | __dir__(self)\n", + " | Default dir() implementation.\n", + " | \n", + " | __getattr__(self, name)\n", + " | \n", + " | __repr__(self)\n", + " | Return repr(self).\n", + " | \n", + " | __setattr__(self, name, value)\n", + " | Implement setattr(self, name, value).\n", + " | \n", + " | add_module(self, name, module)\n", + " | Adds a child module to the current module.\n", + " | \n", + " | The module can be accessed as an attribute using the given name.\n", + " | \n", + " | Args:\n", + " | name (string): name of the child module. The child module can be\n", + " | accessed from this module using the given name\n", + " | module (Module): child module to be added to the module.\n", + " | \n", + " | apply(self, fn)\n", + " | Applies ``fn`` recursively to every submodule (as returned by ``.children()``)\n", + " | as well as self. Typical use includes initializing the parameters of a model\n", + " | (see also :ref:`nn-init-doc`).\n", + " | \n", + " | Args:\n", + " | fn (:class:`Module` -> None): function to be applied to each submodule\n", + " | \n", + " | Returns:\n", + " | Module: self\n", + " | \n", + " | Example::\n", + " | \n", + " | >>> @torch.no_grad()\n", + " | >>> def init_weights(m):\n", + " | >>> print(m)\n", + " | >>> if type(m) == nn.Linear:\n", + " | >>> m.weight.fill_(1.0)\n", + " | >>> print(m.weight)\n", + " | >>> net = nn.Sequential(nn.Linear(2, 2), nn.Linear(2, 2))\n", + " | >>> net.apply(init_weights)\n", + " | Linear(in_features=2, out_features=2, bias=True)\n", + " | Parameter containing:\n", + " | tensor([[ 1., 1.],\n", + " | [ 1., 1.]])\n", + " | Linear(in_features=2, out_features=2, bias=True)\n", + " | Parameter containing:\n", + " | tensor([[ 1., 1.],\n", + " | [ 1., 1.]])\n", + " | Sequential(\n", + " | (0): Linear(in_features=2, out_features=2, bias=True)\n", + " | (1): Linear(in_features=2, out_features=2, bias=True)\n", + " | )\n", + " | Sequential(\n", + " | (0): Linear(in_features=2, out_features=2, bias=True)\n", + " | (1): Linear(in_features=2, out_features=2, bias=True)\n", + " | )\n", + " | \n", + " | bfloat16(self)\n", + " | Casts all floating point parameters and buffers to ``bfloat16`` datatype.\n", + " | \n", + " | Returns:\n", + " | Module: self\n", + " | \n", + " | buffers(self, recurse=True)\n", + " | Returns an iterator over module buffers.\n", + " | \n", + " | Args:\n", + " | recurse (bool): if True, then yields buffers of this module\n", + " | and all submodules. Otherwise, yields only buffers that\n", + " | are direct members of this module.\n", + " | \n", + " | Yields:\n", + " | torch.Tensor: module buffer\n", + " | \n", + " | Example::\n", + " | \n", + " | >>> for buf in model.buffers():\n", + " | >>> print(type(buf), buf.size())\n", + " | (20L,)\n", + " | (20L, 1L, 5L, 5L)\n", + " | \n", + " | children(self)\n", + " | Returns an iterator over immediate children modules.\n", + " | \n", + " | Yields:\n", + " | Module: a child module\n", + " | \n", + " | cpu(self)\n", + " | Moves all model parameters and buffers to the CPU.\n", + " | \n", + " | Returns:\n", + " | Module: self\n", + " | \n", + " | cuda(self, device=None)\n", + " | Moves all model parameters and buffers to the GPU.\n", + " | \n", + " | This also makes associated parameters and buffers different objects. So\n", + " | it should be called before constructing optimizer if the module will\n", + " | live on GPU while being optimized.\n", + " | \n", + " | Arguments:\n", + " | device (int, optional): if specified, all parameters will be\n", + " | copied to that device\n", + " | \n", + " | Returns:\n", + " | Module: self\n", + " | \n", + " | double(self)\n", + " | Casts all floating point parameters and buffers to ``double`` datatype.\n", + " | \n", + " | Returns:\n", + " | Module: self\n", + " | \n", + " | eval(self)\n", + " | Sets the module in evaluation mode.\n", + " | \n", + " | This has any effect only on certain modules. See documentations of\n", + " | particular modules for details of their behaviors in training/evaluation\n", + " | mode, if they are affected, e.g. :class:`Dropout`, :class:`BatchNorm`,\n", + " | etc.\n", + " | \n", + " | This is equivalent with :meth:`self.train(False) `.\n", + " | \n", + " | Returns:\n", + " | Module: self\n", + " | \n", + " | float(self)\n", + " | Casts all floating point parameters and buffers to float datatype.\n", + " | \n", + " | Returns:\n", + " | Module: self\n", + " | \n", + " | half(self)\n", + " | Casts all floating point parameters and buffers to ``half`` datatype.\n", + " | \n", + " | Returns:\n", + " | Module: self\n", + " | \n", + " | load_state_dict(self, state_dict, strict=True)\n", + " | Copies parameters and buffers from :attr:`state_dict` into\n", + " | this module and its descendants. If :attr:`strict` is ``True``, then\n", + " | the keys of :attr:`state_dict` must exactly match the keys returned\n", + " | by this module's :meth:`~torch.nn.Module.state_dict` function.\n", + " | \n", + " | Arguments:\n", + " | state_dict (dict): a dict containing parameters and\n", + " | persistent buffers.\n", + " | strict (bool, optional): whether to strictly enforce that the keys\n", + " | in :attr:`state_dict` match the keys returned by this module's\n", + " | :meth:`~torch.nn.Module.state_dict` function. Default: ``True``\n", + " | \n", + " | Returns:\n", + " | ``NamedTuple`` with ``missing_keys`` and ``unexpected_keys`` fields:\n", + " | * **missing_keys** is a list of str containing the missing keys\n", + " | * **unexpected_keys** is a list of str containing the unexpected keys\n", + " | \n", + " | modules(self)\n", + " | Returns an iterator over all modules in the network.\n", + " | \n", + " | Yields:\n", + " | Module: a module in the network\n", + " | \n", + " | Note:\n", + " | Duplicate modules are returned only once. In the following\n", + " | example, ``l`` will be returned only once.\n", + " | \n", + " | Example::\n", + " | \n", + " | >>> l = nn.Linear(2, 2)\n", + " | >>> net = nn.Sequential(l, l)\n", + " | >>> for idx, m in enumerate(net.modules()):\n", + " | print(idx, '->', m)\n", + " | \n", + " | 0 -> Sequential(\n", + " | (0): Linear(in_features=2, out_features=2, bias=True)\n", + " | (1): Linear(in_features=2, out_features=2, bias=True)\n", + " | )\n", + " | 1 -> Linear(in_features=2, out_features=2, bias=True)\n", + " | \n", + " | named_buffers(self, prefix='', recurse=True)\n", + " | Returns an iterator over module buffers, yielding both the\n", + " | name of the buffer as well as the buffer itself.\n", + " | \n", + " | Args:\n", + " | prefix (str): prefix to prepend to all buffer names.\n", + " | recurse (bool): if True, then yields buffers of this module\n", + " | and all submodules. Otherwise, yields only buffers that\n", + " | are direct members of this module.\n", + " | \n", + " | Yields:\n", + " | (string, torch.Tensor): Tuple containing the name and buffer\n", + " | \n", + " | Example::\n", + " | \n", + " | >>> for name, buf in self.named_buffers():\n", + " | >>> if name in ['running_var']:\n", + " | >>> print(buf.size())\n", + " | \n", + " | named_children(self)\n", + " | Returns an iterator over immediate children modules, yielding both\n", + " | the name of the module as well as the module itself.\n", + " | \n", + " | Yields:\n", + " | (string, Module): Tuple containing a name and child module\n", + " | \n", + " | Example::\n", + " | \n", + " | >>> for name, module in model.named_children():\n", + " | >>> if name in ['conv4', 'conv5']:\n", + " | >>> print(module)\n", + " | \n", + " | named_modules(self, memo=None, prefix='')\n", + " | Returns an iterator over all modules in the network, yielding\n", + " | both the name of the module as well as the module itself.\n", + " | \n", + " | Yields:\n", + " | (string, Module): Tuple of name and module\n", + " | \n", + " | Note:\n", + " | Duplicate modules are returned only once. In the following\n", + " | example, ``l`` will be returned only once.\n", + " | \n", + " | Example::\n", + " | \n", + " | >>> l = nn.Linear(2, 2)\n", + " | >>> net = nn.Sequential(l, l)\n", + " | >>> for idx, m in enumerate(net.named_modules()):\n", + " | print(idx, '->', m)\n", + " | \n", + " | 0 -> ('', Sequential(\n", + " | (0): Linear(in_features=2, out_features=2, bias=True)\n", + " | (1): Linear(in_features=2, out_features=2, bias=True)\n", + " | ))\n", + " | 1 -> ('0', Linear(in_features=2, out_features=2, bias=True))\n", + " | \n", + " | named_parameters(self, prefix='', recurse=True)\n", + " | Returns an iterator over module parameters, yielding both the\n", + " | name of the parameter as well as the parameter itself.\n", + " | \n", + " | Args:\n", + " | prefix (str): prefix to prepend to all parameter names.\n", + " | recurse (bool): if True, then yields parameters of this module\n", + " | and all submodules. Otherwise, yields only parameters that\n", + " | are direct members of this module.\n", + " | \n", + " | Yields:\n", + " | (string, Parameter): Tuple containing the name and parameter\n", + " | \n", + " | Example::\n", + " | \n", + " | >>> for name, param in self.named_parameters():\n", + " | >>> if name in ['bias']:\n", + " | >>> print(param.size())\n", + " | \n", + " | parameters(self, recurse=True)\n", + " | Returns an iterator over module parameters.\n", + " | \n", + " | This is typically passed to an optimizer.\n", + " | \n", + " | Args:\n", + " | recurse (bool): if True, then yields parameters of this module\n", + " | and all submodules. Otherwise, yields only parameters that\n", + " | are direct members of this module.\n", + " | \n", + " | Yields:\n", + " | Parameter: module parameter\n", + " | \n", + " | Example::\n", + " | \n", + " | >>> for param in model.parameters():\n", + " | >>> print(type(param), param.size())\n", + " | (20L,)\n", + " | (20L, 1L, 5L, 5L)\n", + " | \n", + " | register_backward_hook(self, hook)\n", + " | Registers a backward hook on the module.\n", + " | \n", + " | The hook will be called every time the gradients with respect to module\n", + " | inputs are computed. The hook should have the following signature::\n", + " | \n", + " | hook(module, grad_input, grad_output) -> Tensor or None\n", + " | \n", + " | The :attr:`grad_input` and :attr:`grad_output` may be tuples if the\n", + " | module has multiple inputs or outputs. The hook should not modify its\n", + " | arguments, but it can optionally return a new gradient with respect to\n", + " | input that will be used in place of :attr:`grad_input` in subsequent\n", + " | computations.\n", + " | \n", + " | Returns:\n", + " | :class:`torch.utils.hooks.RemovableHandle`:\n", + " | a handle that can be used to remove the added hook by calling\n", + " | ``handle.remove()``\n", + " | \n", + " | .. warning ::\n", + " | \n", + " | The current implementation will not have the presented behavior\n", + " | for complex :class:`Module` that perform many operations.\n", + " | In some failure cases, :attr:`grad_input` and :attr:`grad_output` will only\n", + " | contain the gradients for a subset of the inputs and outputs.\n", + " | For such :class:`Module`, you should use :func:`torch.Tensor.register_hook`\n", + " | directly on a specific input or output to get the required gradients.\n", + " | \n", + " | register_buffer(self, name, tensor)\n", + " | Adds a persistent buffer to the module.\n", + " | \n", + " | This is typically used to register a buffer that should not to be\n", + " | considered a model parameter. For example, BatchNorm's ``running_mean``\n", + " | is not a parameter, but is part of the persistent state.\n", + " | \n", + " | Buffers can be accessed as attributes using given names.\n", + " | \n", + " | Args:\n", + " | name (string): name of the buffer. The buffer can be accessed\n", + " | from this module using the given name\n", + " | tensor (Tensor): buffer to be registered.\n", + " | \n", + " | Example::\n", + " | \n", + " | >>> self.register_buffer('running_mean', torch.zeros(num_features))\n", + " | \n", + " | register_forward_hook(self, hook)\n", + " | Registers a forward hook on the module.\n", + " | \n", + " | The hook will be called every time after :func:`forward` has computed an output.\n", + " | It should have the following signature::\n", + " | \n", + " | hook(module, input, output) -> None or modified output\n", + " | \n", + " | The hook can modify the output. It can modify the input inplace but\n", + " | it will not have effect on forward since this is called after\n", + " | :func:`forward` is called.\n", + " | \n", + " | Returns:\n", + " | :class:`torch.utils.hooks.RemovableHandle`:\n", + " | a handle that can be used to remove the added hook by calling\n", + " | ``handle.remove()``\n", + " | \n", + " | register_forward_pre_hook(self, hook)\n", + " | Registers a forward pre-hook on the module.\n", + " | \n", + " | The hook will be called every time before :func:`forward` is invoked.\n", + " | It should have the following signature::\n", + " | \n", + " | hook(module, input) -> None or modified input\n", + " | \n", + " | The hook can modify the input. User can either return a tuple or a\n", + " | single modified value in the hook. We will wrap the value into a tuple\n", + " | if a single value is returned(unless that value is already a tuple).\n", + " | \n", + " | Returns:\n", + " | :class:`torch.utils.hooks.RemovableHandle`:\n", + " | a handle that can be used to remove the added hook by calling\n", + " | ``handle.remove()``\n", + " | \n", + " | register_parameter(self, name, param)\n", + " | Adds a parameter to the module.\n", + " | \n", + " | The parameter can be accessed as an attribute using given name.\n", + " | \n", + " | Args:\n", + " | name (string): name of the parameter. The parameter can be accessed\n", + " | from this module using the given name\n", + " | param (Parameter): parameter to be added to the module.\n", + " | \n", + " | requires_grad_(self, requires_grad=True)\n", + " | Change if autograd should record operations on parameters in this\n", + " | module.\n", + " | \n", + " | This method sets the parameters' :attr:`requires_grad` attributes\n", + " | in-place.\n", + " | \n", + " | This method is helpful for freezing part of the module for finetuning\n", + " | or training parts of a model individually (e.g., GAN training).\n", + " | \n", + " | Args:\n", + " | requires_grad (bool): whether autograd should record operations on\n", + " | parameters in this module. Default: ``True``.\n", + " | \n", + " | Returns:\n", + " | Module: self\n", + " | \n", + " | share_memory(self)\n", + " | \n", + " | state_dict(self, destination=None, prefix='', keep_vars=False)\n", + " | Returns a dictionary containing a whole state of the module.\n", + " | \n", + " | Both parameters and persistent buffers (e.g. running averages) are\n", + " | included. Keys are corresponding parameter and buffer names.\n", + " | \n", + " | Returns:\n", + " | dict:\n", + " | a dictionary containing a whole state of the module\n", + " | \n", + " | Example::\n", + " | \n", + " | >>> module.state_dict().keys()\n", + " | ['bias', 'weight']\n", + " | \n", + " | to(self, *args, **kwargs)\n", + " | Moves and/or casts the parameters and buffers.\n", + " | \n", + " | This can be called as\n", + " | \n", + " | .. function:: to(device=None, dtype=None, non_blocking=False)\n", + " | \n", + " | .. function:: to(dtype, non_blocking=False)\n", + " | \n", + " | .. function:: to(tensor, non_blocking=False)\n", + " | \n", + " | .. function:: to(memory_format=torch.channels_last)\n", + " | \n", + " | Its signature is similar to :meth:`torch.Tensor.to`, but only accepts\n", + " | floating point desired :attr:`dtype` s. In addition, this method will\n", + " | only cast the floating point parameters and buffers to :attr:`dtype`\n", + " | (if given). The integral parameters and buffers will be moved\n", + " | :attr:`device`, if that is given, but with dtypes unchanged. When\n", + " | :attr:`non_blocking` is set, it tries to convert/move asynchronously\n", + " | with respect to the host if possible, e.g., moving CPU Tensors with\n", + " | pinned memory to CUDA devices.\n", + " | \n", + " | See below for examples.\n", + " | \n", + " | .. note::\n", + " | This method modifies the module in-place.\n", + " | \n", + " | Args:\n", + " | device (:class:`torch.device`): the desired device of the parameters\n", + " | and buffers in this module\n", + " | dtype (:class:`torch.dtype`): the desired floating point type of\n", + " | the floating point parameters and buffers in this module\n", + " | tensor (torch.Tensor): Tensor whose dtype and device are the desired\n", + " | dtype and device for all parameters and buffers in this module\n", + " | memory_format (:class:`torch.memory_format`): the desired memory\n", + " | format for 4D parameters and buffers in this module (keyword\n", + " | only argument)\n", + " | \n", + " | Returns:\n", + " | Module: self\n", + " | \n", + " | Example::\n", + " | \n", + " | >>> linear = nn.Linear(2, 2)\n", + " | >>> linear.weight\n", + " | Parameter containing:\n", + " | tensor([[ 0.1913, -0.3420],\n", + " | [-0.5113, -0.2325]])\n", + " | >>> linear.to(torch.double)\n", + " | Linear(in_features=2, out_features=2, bias=True)\n", + " | >>> linear.weight\n", + " | Parameter containing:\n", + " | tensor([[ 0.1913, -0.3420],\n", + " | [-0.5113, -0.2325]], dtype=torch.float64)\n", + " | >>> gpu1 = torch.device(\"cuda:1\")\n", + " | >>> linear.to(gpu1, dtype=torch.half, non_blocking=True)\n", + " | Linear(in_features=2, out_features=2, bias=True)\n", + " | >>> linear.weight\n", + " | Parameter containing:\n", + " | tensor([[ 0.1914, -0.3420],\n", + " | [-0.5112, -0.2324]], dtype=torch.float16, device='cuda:1')\n", + " | >>> cpu = torch.device(\"cpu\")\n", + " | >>> linear.to(cpu)\n", + " | Linear(in_features=2, out_features=2, bias=True)\n", + " | >>> linear.weight\n", + " | Parameter containing:\n", + " | tensor([[ 0.1914, -0.3420],\n", + " | [-0.5112, -0.2324]], dtype=torch.float16)\n", + " | \n", + " | train(self, mode=True)\n", + " | Sets the module in training mode.\n", + " | \n", + " | This has any effect only on certain modules. See documentations of\n", + " | particular modules for details of their behaviors in training/evaluation\n", + " | mode, if they are affected, e.g. :class:`Dropout`, :class:`BatchNorm`,\n", + " | etc.\n", + " | \n", + " | Args:\n", + " | mode (bool): whether to set training mode (``True``) or evaluation\n", + " | mode (``False``). Default: ``True``.\n", + " | \n", + " | Returns:\n", + " | Module: self\n", + " | \n", + " | type(self, dst_type)\n", + " | Casts all parameters and buffers to :attr:`dst_type`.\n", + " | \n", + " | Arguments:\n", + " | dst_type (type or string): the desired type\n", + " | \n", + " | Returns:\n", + " | Module: self\n", + " | \n", + " | zero_grad(self)\n", + " | Sets gradients of all model parameters to zero.\n", + " | \n", + " | ----------------------------------------------------------------------\n", + " | Data descriptors inherited from torch.nn.modules.module.Module:\n", + " | \n", + " | __dict__\n", + " | dictionary for instance variables (if defined)\n", + " | \n", + " | __weakref__\n", + " | list of weak references to the object (if defined)\n", + " | \n", + " | ----------------------------------------------------------------------\n", + " | Data and other attributes inherited from torch.nn.modules.module.Module:\n", + " | \n", + " | dump_patches = False\n", + "\n" + ] + } + ], + "source": [ + "help(nn.Conv2d)" + ] + }, + { + "cell_type": "code", + "execution_count": 58, + "metadata": { + "ExecuteTime": { + "end_time": "2020-10-13T05:12:53.507346Z", + "start_time": "2020-10-13T05:12:53.500655Z" } }, "outputs": [], @@ -361,11 +1071,11 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 59, "metadata": { "ExecuteTime": { - "end_time": "2020-10-03T05:07:42.484954Z", - "start_time": "2020-10-03T05:07:42.472990Z" + "end_time": "2020-10-13T05:12:53.668748Z", + "start_time": "2020-10-13T05:12:53.657666Z" } }, "outputs": [ @@ -374,11 +1084,21 @@ "output_type": "stream", "text": [ "Net(\n", - " (conv1): Conv2d(1, 6, kernel_size=(3, 3), stride=(1, 1))\n", - " (conv2): Conv2d(6, 16, kernel_size=(3, 3), stride=(1, 1))\n", - " (fc1): Linear(in_features=8464, out_features=120, bias=True)\n", - " (fc2): Linear(in_features=120, out_features=84, bias=True)\n", - " (fc3): Linear(in_features=84, out_features=4, bias=True)\n", + " (conv): Sequential(\n", + " (0): Conv2d(1, 6, kernel_size=(3, 3), stride=(1, 1))\n", + " (1): ReLU()\n", + " (2): MaxPool2d(kernel_size=2, stride=2, padding=0, dilation=1, ceil_mode=False)\n", + " (3): Conv2d(6, 16, kernel_size=(3, 3), stride=(1, 1))\n", + " (4): ReLU()\n", + " (5): MaxPool2d(kernel_size=2, stride=2, padding=0, dilation=1, ceil_mode=False)\n", + " )\n", + " (head): Sequential(\n", + " (0): Linear(in_features=8464, out_features=120, bias=True)\n", + " (1): ReLU()\n", + " (2): Linear(in_features=120, out_features=84, bias=True)\n", + " (3): ReLU()\n", + " (4): Linear(in_features=84, out_features=4, bias=True)\n", + " )\n", ")\n" ] } @@ -389,6 +1109,61 @@ "print(net)" ] }, + { + "cell_type": "code", + "execution_count": 60, + "metadata": { + "ExecuteTime": { + "end_time": "2020-10-13T05:12:53.854476Z", + "start_time": "2020-10-13T05:12:53.825261Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "========================================================================\n", + " Kernel Shape Output Shape Params Mult-Adds\n", + "Layer \n", + "0_conv.Conv2d_0 [1, 6, 3, 3] [1, 6, 97, 97] 60.0 508.086k\n", + "1_conv.ReLU_1 - [1, 6, 97, 97] - -\n", + "2_conv.MaxPool2d_2 - [1, 6, 48, 48] - -\n", + "3_conv.Conv2d_3 [6, 16, 3, 3] [1, 16, 46, 46] 880.0 1.828224M\n", + "4_conv.ReLU_4 - [1, 16, 46, 46] - -\n", + "5_conv.MaxPool2d_5 - [1, 16, 23, 23] - -\n", + "6_head.Linear_0 [8464, 120] [1, 120] 1.0158M 1.01568M\n", + "7_head.ReLU_1 - [1, 120] - -\n", + "8_head.Linear_2 [120, 84] [1, 84] 10.164k 10.08k\n", + "9_head.ReLU_3 - [1, 84] - -\n", + "10_head.Linear_4 [84, 4] [1, 4] 340.0 336.0\n", + "------------------------------------------------------------------------\n", + " Totals\n", + "Total params 1.027244M\n", + "Trainable params 1.027244M\n", + "Non-trainable params 0.0\n", + "Mult-Adds 3.362406M\n", + "========================================================================\n" + ] + }, + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 60, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from deep_ml_curriculum.torchsummaryX import summary\n", + "# We can also summarise the number of parameters in each layer\n", + "summary(net, torch.rand((1, 1, 99, 99)))\n", + "1" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -404,11 +1179,11 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 61, "metadata": { "ExecuteTime": { - "end_time": "2020-10-03T05:07:44.796878Z", - "start_time": "2020-10-03T05:07:44.780738Z" + "end_time": "2020-10-13T05:12:54.130240Z", + "start_time": "2020-10-13T05:12:54.123436Z" } }, "outputs": [ @@ -416,7 +1191,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "tensor([[ 0.0480, -0.0797, -0.0579, 0.0829]], grad_fn=)\n" + "tensor([[ 0.0494, -0.0630, 0.0044, -0.0264]], grad_fn=)\n" ] } ], @@ -444,21 +1219,21 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 62, "metadata": { "ExecuteTime": { - "end_time": "2020-10-03T05:07:46.848641Z", - "start_time": "2020-10-03T05:07:46.834233Z" + "end_time": "2020-10-13T05:12:54.466722Z", + "start_time": "2020-10-13T05:12:54.460610Z" } }, "outputs": [ { "data": { "text/plain": [ - "" + "" ] }, - "execution_count": 10, + "execution_count": 62, "metadata": {}, "output_type": "execute_result" } @@ -484,11 +1259,11 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 63, "metadata": { "ExecuteTime": { - "end_time": "2020-10-03T05:07:48.975171Z", - "start_time": "2020-10-03T05:07:48.231216Z" + "end_time": "2020-10-13T05:12:54.729924Z", + "start_time": "2020-10-13T05:12:54.627334Z" } }, "outputs": [], @@ -511,11 +1286,11 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 68, "metadata": { "ExecuteTime": { - "end_time": "2020-10-03T05:08:02.875719Z", - "start_time": "2020-10-03T05:08:02.867465Z" + "end_time": "2020-10-13T05:19:34.088055Z", + "start_time": "2020-10-13T05:19:34.082007Z" } }, "outputs": [], @@ -523,25 +1298,29 @@ "def train(model, x, y, criterion, optimizer, n_epochs=1, bs=64):\n", " # Set model in train mode\n", " model.train()\n", - " running_loss = 0.0\n", - " for epoch in range(n_epochs):\n", + " for epoch in tqdm(range(n_epochs)):\n", + " running_loss = 0.0\n", " for i in range((x_train.shape[0] - 1) // bs + 1):\n", + " \n", " # Let's divide the data in batches\n", " start_i = i * bs\n", " end_i = start_i + bs\n", " inputs = x_train[start_i:end_i].unsqueeze(1).float()\n", " labels = y_train[start_i:end_i].long()\n", + " \n", " # zero the parameter gradients\n", " optimizer.zero_grad()\n", + " \n", " # forward + backward + optimize\n", " outputs = model(inputs) # Get the prediction here\n", " loss = criterion(outputs, labels) # Calculate loss\n", " loss.backward() # Do backpropagation\n", " optimizer.step() # Update weights\n", + " \n", " # print statistics\n", " running_loss += loss.item()\n", " if i % 10 == 9:\n", - " print(\"[%d, %5d] loss: %.3f\" % (epoch + 1, i + 1, running_loss / 2000))\n", + " print(\"[%d, %5d] loss: %.3g\" % (epoch + 1, i + 1, running_loss / 2000))\n", " running_loss = 0.0\n", "\n", " print(\"Finished Training\")\n", @@ -550,11 +1329,11 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 69, "metadata": { "ExecuteTime": { - "end_time": "2020-10-03T05:08:03.961431Z", - "start_time": "2020-10-03T05:08:03.956068Z" + "end_time": "2020-10-13T05:19:34.216649Z", + "start_time": "2020-10-13T05:19:34.212423Z" } }, "outputs": [], @@ -578,51 +1357,57 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 70, "metadata": { "ExecuteTime": { - "end_time": "2020-10-03T05:08:37.458536Z", - "start_time": "2020-10-03T05:08:04.946396Z" + "end_time": "2020-10-13T05:19:49.206830Z", + "start_time": "2020-10-13T05:19:34.370631Z" } }, "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[1, 10] loss: 0.007\n", - "[1, 20] loss: 0.007\n", - "[1, 30] loss: 0.007\n", - "[1, 40] loss: 0.007\n", - "[1, 50] loss: 0.007\n", - "[1, 60] loss: 0.007\n", - "[1, 70] loss: 0.007\n", - "[1, 80] loss: 0.007\n", - "[1, 90] loss: 0.006\n", - "[1, 100] loss: 0.006\n", - "[1, 110] loss: 0.006\n", - "[1, 120] loss: 0.006\n", - "[1, 130] loss: 0.006\n", - "[1, 140] loss: 0.006\n", - "[1, 150] loss: 0.006\n", - "[1, 160] loss: 0.006\n", - "[1, 170] loss: 0.006\n", - "[1, 180] loss: 0.006\n", - "[1, 190] loss: 0.006\n", - "[1, 200] loss: 0.006\n", - "Finished Training\n", - "2371 4417\n" - ] - }, { "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "62b9d73c0f7244009130dfa8d6bba245", + "version_major": 2, + "version_minor": 0 + }, "text/plain": [ - "53.678967625084894" + "HBox(children=(FloatProgress(value=0.0, max=1.0), HTML(value='')))" ] }, - "execution_count": 14, "metadata": {}, - "output_type": "execute_result" + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1, 10] loss: 0.00598\n", + "[1, 20] loss: 0.00589\n", + "[1, 30] loss: 0.00604\n", + "[1, 40] loss: 0.00592\n", + "[1, 50] loss: 0.00596\n", + "[1, 60] loss: 0.00591\n", + "[1, 70] loss: 0.00569\n", + "[1, 80] loss: 0.00576\n", + "[1, 90] loss: 0.00595\n", + "[1, 100] loss: 0.00584\n", + "[1, 110] loss: 0.00582\n", + "[1, 120] loss: 0.00564\n", + "[1, 130] loss: 0.0058\n", + "[1, 140] loss: 0.00568\n", + "[1, 150] loss: 0.00569\n", + "[1, 160] loss: 0.00567\n", + "[1, 170] loss: 0.00559\n", + "[1, 180] loss: 0.00554\n", + "[1, 190] loss: 0.00555\n", + "[1, 200] loss: 0.00561\n", + "\n", + "Finished Training\n", + "2371 4417\n", + "Accuracy: 53.678967625084894\n" + ] } ], "source": [ @@ -642,132 +1427,139 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 71, "metadata": { "ExecuteTime": { - "end_time": "2020-10-03T05:17:28.041501Z", - "start_time": "2020-10-03T05:15:07.737878Z" - } + "end_time": "2020-10-13T05:20:36.368158Z", + "start_time": "2020-10-13T05:19:54.642568Z" + }, + "scrolled": true }, "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "37f859ff1cfb40c7b7f17d5c085f81dd", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "HBox(children=(FloatProgress(value=0.0, max=5.0), HTML(value='')))" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, { "name": "stdout", "output_type": "stream", "text": [ - "[1, 10] loss: 0.006\n", - "[1, 20] loss: 0.006\n", - "[1, 30] loss: 0.006\n", - "[1, 40] loss: 0.006\n", - "[1, 50] loss: 0.006\n", - "[1, 60] loss: 0.006\n", - "[1, 70] loss: 0.006\n", - "[1, 80] loss: 0.006\n", - "[1, 90] loss: 0.006\n", - "[1, 100] loss: 0.006\n", - "[1, 110] loss: 0.006\n", - "[1, 120] loss: 0.006\n", - "[1, 130] loss: 0.006\n", - "[1, 140] loss: 0.006\n", - "[1, 150] loss: 0.006\n", - "[1, 160] loss: 0.006\n", - "[1, 170] loss: 0.006\n", - "[1, 180] loss: 0.006\n", - "[1, 190] loss: 0.006\n", - "[1, 200] loss: 0.006\n", - "[2, 10] loss: 0.011\n", - "[2, 20] loss: 0.006\n", - "[2, 30] loss: 0.006\n", - "[2, 40] loss: 0.006\n", - "[2, 50] loss: 0.006\n", - "[2, 60] loss: 0.006\n", - "[2, 70] loss: 0.006\n", - "[2, 80] loss: 0.006\n", - "[2, 90] loss: 0.006\n", - "[2, 100] loss: 0.006\n", - "[2, 110] loss: 0.006\n", - "[2, 120] loss: 0.006\n", - "[2, 130] loss: 0.006\n", - "[2, 140] loss: 0.006\n", - "[2, 150] loss: 0.006\n", - "[2, 160] loss: 0.006\n", - "[2, 170] loss: 0.006\n", - "[2, 180] loss: 0.006\n", - "[2, 190] loss: 0.006\n", - "[2, 200] loss: 0.006\n", - "[3, 10] loss: 0.011\n", - "[3, 20] loss: 0.006\n", - "[3, 30] loss: 0.006\n", - "[3, 40] loss: 0.006\n", - "[3, 50] loss: 0.006\n", - "[3, 60] loss: 0.006\n", - "[3, 70] loss: 0.006\n", - "[3, 80] loss: 0.006\n", - "[3, 90] loss: 0.006\n", - "[3, 100] loss: 0.006\n", - "[3, 110] loss: 0.006\n", - "[3, 120] loss: 0.006\n", - "[3, 130] loss: 0.006\n", - "[3, 140] loss: 0.006\n", - "[3, 150] loss: 0.006\n", - "[3, 160] loss: 0.006\n", - "[3, 170] loss: 0.006\n", - "[3, 180] loss: 0.006\n", - "[3, 190] loss: 0.006\n", - "[3, 200] loss: 0.006\n", - "[4, 10] loss: 0.011\n", - "[4, 20] loss: 0.006\n", - "[4, 30] loss: 0.006\n", - "[4, 40] loss: 0.006\n", - "[4, 50] loss: 0.006\n", - "[4, 60] loss: 0.006\n", - "[4, 70] loss: 0.006\n", - "[4, 80] loss: 0.006\n", - "[4, 90] loss: 0.006\n", - "[4, 100] loss: 0.006\n", - "[4, 110] loss: 0.006\n", - "[4, 120] loss: 0.006\n", - "[4, 130] loss: 0.006\n", - "[4, 140] loss: 0.006\n", - "[4, 150] loss: 0.006\n", - "[4, 160] loss: 0.006\n", - "[4, 170] loss: 0.006\n", - "[4, 180] loss: 0.006\n", - "[4, 190] loss: 0.006\n", - "[4, 200] loss: 0.006\n", - "[5, 10] loss: 0.011\n", - "[5, 20] loss: 0.006\n", - "[5, 30] loss: 0.006\n", - "[5, 40] loss: 0.006\n", - "[5, 50] loss: 0.006\n", - "[5, 60] loss: 0.006\n", - "[5, 70] loss: 0.006\n", - "[5, 80] loss: 0.006\n", - "[5, 90] loss: 0.006\n", - "[5, 100] loss: 0.006\n", - "[5, 110] loss: 0.006\n", - "[5, 120] loss: 0.006\n", - "[5, 130] loss: 0.006\n", - "[5, 140] loss: 0.006\n", - "[5, 150] loss: 0.006\n", - "[5, 160] loss: 0.006\n", - "[5, 170] loss: 0.006\n", - "[5, 180] loss: 0.006\n", - "[5, 190] loss: 0.006\n", - "[5, 200] loss: 0.006\n", + "[1, 10] loss: 0.00551\n", + "[1, 20] loss: 0.00548\n", + "[1, 30] loss: 0.00579\n", + "[1, 40] loss: 0.00569\n", + "[1, 50] loss: 0.00576\n", + "[1, 60] loss: 0.00576\n", + "[1, 70] loss: 0.00548\n", + "[1, 80] loss: 0.0056\n", + "[1, 90] loss: 0.00585\n", + "[1, 100] loss: 0.00578\n", + "[1, 110] loss: 0.00574\n", + "[1, 120] loss: 0.00556\n", + "[1, 130] loss: 0.00574\n", + "[1, 140] loss: 0.00562\n", + "[1, 150] loss: 0.00566\n", + "[1, 160] loss: 0.00564\n", + "[1, 170] loss: 0.00558\n", + "[1, 180] loss: 0.00554\n", + "[1, 190] loss: 0.00554\n", + "[1, 200] loss: 0.00561\n", + "[2, 10] loss: 0.00551\n", + "[2, 20] loss: 0.00548\n", + "[2, 30] loss: 0.00579\n", + "[2, 40] loss: 0.00569\n", + "[2, 50] loss: 0.00576\n", + "[2, 60] loss: 0.00576\n", + "[2, 70] loss: 0.00548\n", + "[2, 80] loss: 0.0056\n", + "[2, 90] loss: 0.00585\n", + "[2, 100] loss: 0.00578\n", + "[2, 110] loss: 0.00574\n", + "[2, 120] loss: 0.00556\n", + "[2, 130] loss: 0.00574\n", + "[2, 140] loss: 0.00562\n", + "[2, 150] loss: 0.00566\n", + "[2, 160] loss: 0.00564\n", + "[2, 170] loss: 0.00558\n", + "[2, 180] loss: 0.00554\n", + "[2, 190] loss: 0.00554\n", + "[2, 200] loss: 0.00561\n", + "[3, 10] loss: 0.00551\n", + "[3, 20] loss: 0.00548\n", + "[3, 30] loss: 0.00579\n", + "[3, 40] loss: 0.00569\n", + "[3, 50] loss: 0.00576\n", + "[3, 60] loss: 0.00576\n", + "[3, 70] loss: 0.00548\n", + "[3, 80] loss: 0.0056\n", + "[3, 90] loss: 0.00585\n", + "[3, 100] loss: 0.00578\n", + "[3, 110] loss: 0.00574\n", + "[3, 120] loss: 0.00556\n", + "[3, 130] loss: 0.00574\n", + "[3, 140] loss: 0.00562\n", + "[3, 150] loss: 0.00566\n", + "[3, 160] loss: 0.00564\n", + "[3, 170] loss: 0.00558\n", + "[3, 180] loss: 0.00554\n", + "[3, 190] loss: 0.00554\n", + "[3, 200] loss: 0.00561\n", + "[4, 10] loss: 0.00551\n", + "[4, 20] loss: 0.00548\n", + "[4, 30] loss: 0.00579\n", + "[4, 40] loss: 0.00569\n", + "[4, 50] loss: 0.00576\n", + "[4, 60] loss: 0.00576\n", + "[4, 70] loss: 0.00548\n", + "[4, 80] loss: 0.0056\n", + "[4, 90] loss: 0.00585\n", + "[4, 100] loss: 0.00578\n", + "[4, 110] loss: 0.00574\n", + "[4, 120] loss: 0.00556\n", + "[4, 130] loss: 0.00574\n", + "[4, 140] loss: 0.00562\n", + "[4, 150] loss: 0.00566\n", + "[4, 160] loss: 0.00564\n", + "[4, 170] loss: 0.00558\n", + "[4, 180] loss: 0.00554\n", + "[4, 190] loss: 0.00554\n", + "[4, 200] loss: 0.00561\n", + "[5, 10] loss: 0.00551\n", + "[5, 20] loss: 0.00548\n", + "[5, 30] loss: 0.00579\n", + "[5, 40] loss: 0.00569\n", + "[5, 50] loss: 0.00576\n", + "[5, 60] loss: 0.00576\n", + "[5, 70] loss: 0.00548\n", + "[5, 80] loss: 0.0056\n", + "[5, 90] loss: 0.00585\n", + "[5, 100] loss: 0.00578\n", + "[5, 110] loss: 0.00574\n", + "[5, 120] loss: 0.00556\n", + "[5, 130] loss: 0.00574\n", + "[5, 140] loss: 0.00562\n", + "[5, 150] loss: 0.00566\n", + "[5, 160] loss: 0.00564\n", + "[5, 170] loss: 0.00558\n", + "[5, 180] loss: 0.00554\n", + "[5, 190] loss: 0.00554\n", + "[5, 200] loss: 0.00561\n", + "\n", "Finished Training\n", "Testing accuracy on unseen data...\n", - "2371 4417\n" + "2371 4417\n", + "Accuracy: 53.678967625084894\n" ] - }, - { - "data": { - "text/plain": [ - "53.678967625084894" - ] - }, - "execution_count": 16, - "metadata": {}, - "output_type": "execute_result" } ], "source": [ @@ -783,7 +1575,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "We trained the same model using `SGD` for 1, 2, and 5 epochs. At some point, it seems like the model is not converging in it got stucked in a local minima. To improve the results we will tray a couple of things:\n", + "We trained the same model using `SGD` for 1, 2, and 5 epochs. At some point, it seems like the model is not converging in it got stuck in a local minima. To improve the results we will tray a couple of things:\n", "\n", "1. Create a new model with `Batch Normalization`, it is often used in modern CNN architectures because it helps to create more general models (regularization) preventing overfitting.\n", "2. Change `SGD` for `Adam` optimizer. `Adam` is known to converge faster than `SGD`.\n", @@ -792,11 +1584,11 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 72, "metadata": { "ExecuteTime": { - "end_time": "2020-10-03T05:19:51.156080Z", - "start_time": "2020-10-03T05:19:51.140932Z" + "end_time": "2020-10-13T05:22:54.896392Z", + "start_time": "2020-10-13T05:22:54.886794Z" } }, "outputs": [], @@ -855,51 +1647,54 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": null, "metadata": { "ExecuteTime": { - "end_time": "2020-10-03T05:25:32.952426Z", - "start_time": "2020-10-03T05:19:52.735628Z" + "start_time": "2020-10-13T05:22:55.453Z" } }, "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[1, 10] loss: 0.072\n", - "[1, 20] loss: 0.014\n", - "[1, 30] loss: 0.004\n", - "[1, 40] loss: 0.002\n", - "[1, 50] loss: 0.001\n", - "[1, 60] loss: 0.000\n", - "[1, 70] loss: 0.000\n", - "[1, 80] loss: 0.000\n", - "[1, 90] loss: 0.000\n", - "[1, 100] loss: 0.000\n", - "[1, 110] loss: 0.000\n", - "[1, 120] loss: 0.000\n", - "[1, 130] loss: 0.000\n", - "[1, 140] loss: 0.000\n", - "[1, 150] loss: 0.000\n", - "[1, 160] loss: 0.000\n", - "[1, 170] loss: 0.000\n", - "[1, 180] loss: 0.000\n", - "[1, 190] loss: 0.000\n", - "[1, 200] loss: 0.000\n", - "Finished Training\n", - "1833 4417\n" - ] - }, { "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "b7ba80bc3839404a9abff6be6e8cfbad", + "version_major": 2, + "version_minor": 0 + }, "text/plain": [ - "41.498754810957664" + "HBox(children=(FloatProgress(value=0.0, max=1.0), HTML(value='')))" ] }, - "execution_count": 18, "metadata": {}, - "output_type": "execute_result" + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1, 10] loss: 0.0716\n", + "[1, 20] loss: 0.0141\n", + "[1, 30] loss: 0.00412\n", + "[1, 40] loss: 0.00163\n", + "[1, 50] loss: 0.000968\n", + "[1, 60] loss: 0.000379\n", + "[1, 70] loss: 0.000479\n", + "[1, 80] loss: 0.000297\n", + "[1, 90] loss: 0.000309\n", + "[1, 100] loss: 0.000187\n", + "[1, 110] loss: 0.000177\n", + "[1, 120] loss: 0.000107\n", + "[1, 130] loss: 0.00012\n", + "[1, 140] loss: 6.42e-05\n", + "[1, 150] loss: 7.21e-05\n", + "[1, 160] loss: 5.12e-05\n", + "[1, 170] loss: 0.000135\n", + "[1, 180] loss: 4.67e-05\n", + "[1, 190] loss: 0.000169\n", + "[1, 200] loss: 0.000174\n", + "\n", + "Finished Training\n" + ] } ], "source": [ @@ -909,6 +1704,18 @@ "test(model, x_test, y_test)" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from deep_ml_curriculum.torchsummaryX import summary\n", + "# We can also summarise the number of parameters in each layer\n", + "summary(net, torch.rand((1, 1, 99, 99)))\n", + "1" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -993,9 +1800,9 @@ "formats": "ipynb,py" }, "kernelspec": { - "display_name": "Python 3", + "display_name": "py37_pytorch", "language": "python", - "name": "python3" + "name": "conda-env-py37_pytorch-py" }, "language_info": { "codemirror_mode": { @@ -1007,7 +1814,20 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.5" + "version": "3.7.0" + }, + "toc": { + "base_numbering": 1, + "nav_menu": {}, + "number_sections": true, + "sideBar": true, + "skip_h1_title": false, + "title_cell": "Table of Contents", + "title_sidebar": "Contents", + "toc_cell": false, + "toc_position": {}, + "toc_section_display": true, + "toc_window_display": true }, "varInspector": { "cols": { diff --git a/notebooks/c02_Intro_to_NN_Part_2/Intro_to_NN_Part_2.py b/notebooks/c02_Intro_to_NN_Part_2/Intro_to_NN_Part_2.py index 733226f..667fae3 100644 --- a/notebooks/c02_Intro_to_NN_Part_2/Intro_to_NN_Part_2.py +++ b/notebooks/c02_Intro_to_NN_Part_2/Intro_to_NN_Part_2.py @@ -9,17 +9,22 @@ # format_version: '1.5' # jupytext_version: 1.6.0 # kernelspec: -# display_name: Python 3 +# display_name: py37_pytorch # language: python -# name: python3 +# name: conda-env-py37_pytorch-py # --- +# + # Let's import some libraries first import torch from torch import optim from torch import nn import torch.nn.functional as F +import numpy as np +from tqdm.auto import tqdm +# - + # # 0. Introduction to Pytorch # There are different architectures for Neural Networks (NNs). Those architectures are defined by blocks called layers. In this notebook we will learn how to use common layers to build a neural networks from scratch. We will also learn how to train the neural network using the `Pytorch` library and evaluate its performance. # @@ -100,7 +105,7 @@ #
# # **NOTE:**
-# Use `nn.maxpoo2d` in Pytorch for 2d Max Pooling. +# Use `nn.maxpool2d` in Pytorch for 2d Max Pooling. #
# # Another important concept of CNNs is pooling, which is a form of non-linear down-sampling. The example below, shows Max pooling with a 2x2 filter and stride = 2. In every sub-region, the max value obtained. @@ -117,6 +122,8 @@ # # In this notebook, we will be using the landmass dataset, which have been preprocessed already. In this dataset, we have images of 4 different types of landmass: 'Chaotic Horizon', 'Fault', 'Horizon', 'Salt Dome'. # +# This is an example of [seismic data](https://en.wikipedia.org/wiki/Reflection_seismology) which is a way of using seismic to image the structure of the Earth, below the surface. These waves are similar to sounds waves in air. The lines represent changes in density below the surface. +# # We will train a CNN to learn how to classify images into those 4 groups. # + @@ -150,7 +157,6 @@ landmassf3_train.classes - # Source: [Neural Networks](https://pytorch.org/tutorials/beginner/blitz/neural_networks_tutorial.html#sphx-glr-beginner-blitz-neural-networks-tutorial-py) # # Now let's implement our first NN from scratch using Pytorch. A typical training procedure for a neural network is as follows: @@ -172,6 +178,9 @@ # #

Define the network

+help(nn.Conv2d) + + class Net(nn.Module): def __init__(self): super(Net, self).__init__() @@ -207,6 +216,11 @@ def num_flat_features(self, x): net = Net() print(net) +from deep_ml_curriculum.torchsummaryX import summary +# We can also summarise the number of parameters in each layer +summary(net, torch.rand((1, 1, 99, 99))) +1 + # Let's try a random 99x99 input. The input image to follow this convention: # # (N, C, W, H) @@ -266,25 +280,29 @@ def num_flat_features(self, x): def train(model, x, y, criterion, optimizer, n_epochs=1, bs=64): # Set model in train mode model.train() - running_loss = 0.0 - for epoch in range(n_epochs): + for epoch in tqdm(range(n_epochs)): + running_loss = 0.0 for i in range((x_train.shape[0] - 1) // bs + 1): + # Let's divide the data in batches start_i = i * bs end_i = start_i + bs inputs = x_train[start_i:end_i].unsqueeze(1).float() labels = y_train[start_i:end_i].long() + # zero the parameter gradients optimizer.zero_grad() + # forward + backward + optimize outputs = model(inputs) # Get the prediction here loss = criterion(outputs, labels) # Calculate loss loss.backward() # Do backpropagation optimizer.step() # Update weights + # print statistics running_loss += loss.item() if i % 10 == 9: - print("[%d, %5d] loss: %.3f" % (epoch + 1, i + 1, running_loss / 2000)) + print("[%d, %5d] loss: %.3g" % (epoch + 1, i + 1, running_loss / 2000)) running_loss = 0.0 print("Finished Training") @@ -324,7 +342,7 @@ def test(model, x, y): print('Accuracy:',test(model, x_test, y_test)) -# We trained the same model using `SGD` for 1, 2, and 5 epochs. At some point, it seems like the model is not converging in it got stucked in a local minima. To improve the results we will tray a couple of things: +# We trained the same model using `SGD` for 1, 2, and 5 epochs. At some point, it seems like the model is not converging in it got stuck in a local minima. To improve the results we will tray a couple of things: # # 1. Create a new model with `Batch Normalization`, it is often used in modern CNN architectures because it helps to create more general models (regularization) preventing overfitting. # 2. Change `SGD` for `Adam` optimizer. `Adam` is known to converge faster than `SGD`. @@ -383,6 +401,11 @@ def forward(self, x): model = train(convnet, x_train, y_train, criterion, optimizer) test(model, x_test, y_test) +from deep_ml_curriculum.torchsummaryX import summary +# We can also summarise the number of parameters in each layer +summary(net, torch.rand((1, 1, 99, 99))) +1 + #
# Exercise 1:
#