Learn practical skills, build real-world projects, and advance your career
Created 4 years ago
import os
import pickle
import h5py
from pathlib import Path
from datetime import datetime
from copy import deepcopy
import numpy as np
import matplotlib.pyplot as plt
import torch
import torch.nn as nn
import torch.optim as optim
import torch.nn.functional as F
import torchvision as tv
import torchvision.transforms as tvTransforms
from torch.utils.data import DataLoader
from torch.utils.dlpack import to_dlpack, from_dlpack
import cupy as cp
from numba import guvectorize, cuda
from typing import Union
%matplotlib inline
pytorchHome = Path.home() / ".pytorch"
dsRoot = pytorchHome / "datasets"
modelDir = Path("pytorchBnnCheckpoints")
modelDir.mkdir(exist_ok=True)
device = torch.device('cuda') if torch.cuda.is_available() else torch.device('cpu')
Neptune Logging
!pip install neptune-client
Collecting neptune-client
Downloading https://files.pythonhosted.org/packages/4a/d6/00edcbff22f7ada15ff7b3e3c21b4cbbdd2bdd54aa72424691ad038c7d66/neptune-client-0.4.119.tar.gz (90kB)
|████████████████████████████████| 92kB 2.4MB/s
Collecting bravado
Downloading https://files.pythonhosted.org/packages/2a/cc/b3c8dadc3f51fa184db10172f031c1c5206b0e67f3207217bbdd326e81a4/bravado-10.6.2-py2.py3-none-any.whl
Requirement already satisfied: click>=7.0 in /usr/local/lib/python3.6/dist-packages (from neptune-client) (7.1.2)
Collecting future>=0.17.1
Downloading https://files.pythonhosted.org/packages/45/0b/38b06fd9b92dc2b68d58b75f900e97884c45bedd2ff83203d933cf5851c9/future-0.18.2.tar.gz (829kB)
|████████████████████████████████| 829kB 8.6MB/s
Collecting py3nvml
Downloading https://files.pythonhosted.org/packages/53/b3/cb30dd8cc1198ae3fdb5a320ca7986d7ca76e23d16415067eafebff8685f/py3nvml-0.2.6-py3-none-any.whl (55kB)
|████████████████████████████████| 61kB 7.1MB/s
Requirement already satisfied: oauthlib>=2.1.0 in /usr/local/lib/python3.6/dist-packages (from neptune-client) (3.1.0)
Requirement already satisfied: pandas in /usr/local/lib/python3.6/dist-packages (from neptune-client) (1.0.5)
Requirement already satisfied: Pillow>=1.1.6 in /usr/local/lib/python3.6/dist-packages (from neptune-client) (7.0.0)
Collecting PyJWT
Downloading https://files.pythonhosted.org/packages/87/8b/6a9f14b5f781697e51259d81657e6048fd31a113229cf346880bb7545565/PyJWT-1.7.1-py2.py3-none-any.whl
Requirement already satisfied: requests>=2.20.0 in /usr/local/lib/python3.6/dist-packages (from neptune-client) (2.23.0)
Requirement already satisfied: requests-oauthlib>=1.0.0 in /usr/local/lib/python3.6/dist-packages (from neptune-client) (1.3.0)
Requirement already satisfied: six>=1.12.0 in /usr/local/lib/python3.6/dist-packages (from neptune-client) (1.15.0)
Collecting websocket-client>=0.35.0
Downloading https://files.pythonhosted.org/packages/4c/5f/f61b420143ed1c8dc69f9eaec5ff1ac36109d52c80de49d66e0c36c3dfdf/websocket_client-0.57.0-py2.py3-none-any.whl (200kB)
|████████████████████████████████| 204kB 14.8MB/s
Collecting GitPython>=2.0.8
Downloading https://files.pythonhosted.org/packages/f9/1e/a45320cab182bf1c8656107b3d4c042e659742822fc6bff150d769a984dd/GitPython-3.1.7-py3-none-any.whl (158kB)
|████████████████████████████████| 163kB 16.6MB/s
Requirement already satisfied: packaging in /usr/local/lib/python3.6/dist-packages (from neptune-client) (20.4)
Collecting msgpack-python
Downloading https://files.pythonhosted.org/packages/8a/20/6eca772d1a5830336f84aca1d8198e5a3f4715cd1c7fc36d3cc7f7185091/msgpack-python-0.5.6.tar.gz (138kB)
|████████████████████████████████| 143kB 16.4MB/s
Collecting bravado-core>=5.16.1
Downloading https://files.pythonhosted.org/packages/76/11/18e9d28a156c33f2d5f15a5e155dc7130250acb0a569255a2b6b307b596d/bravado_core-5.17.0-py2.py3-none-any.whl (67kB)
|████████████████████████████████| 71kB 7.2MB/s
Collecting simplejson
Downloading https://files.pythonhosted.org/packages/73/96/1e6b19045375890068d7342cbe280dd64ae73fd90b9735b5efb8d1e044a1/simplejson-3.17.2-cp36-cp36m-manylinux2010_x86_64.whl (127kB)
|████████████████████████████████| 133kB 16.7MB/s
Requirement already satisfied: python-dateutil in /usr/local/lib/python3.6/dist-packages (from bravado->neptune-client) (2.8.1)
Requirement already satisfied: pyyaml in /usr/local/lib/python3.6/dist-packages (from bravado->neptune-client) (3.13)
Collecting monotonic
Downloading https://files.pythonhosted.org/packages/ac/aa/063eca6a416f397bd99552c534c6d11d57f58f2e94c14780f3bbf818c4cf/monotonic-1.5-py2.py3-none-any.whl
Requirement already satisfied: typing-extensions in /usr/local/lib/python3.6/dist-packages (from bravado->neptune-client) (3.7.4.2)
Collecting xmltodict
Downloading https://files.pythonhosted.org/packages/28/fd/30d5c1d3ac29ce229f6bdc40bbc20b28f716e8b363140c26eff19122d8a5/xmltodict-0.12.0-py2.py3-none-any.whl
Requirement already satisfied: pytz>=2017.2 in /usr/local/lib/python3.6/dist-packages (from pandas->neptune-client) (2018.9)
Requirement already satisfied: numpy>=1.13.3 in /usr/local/lib/python3.6/dist-packages (from pandas->neptune-client) (1.18.5)
Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.6/dist-packages (from requests>=2.20.0->neptune-client) (2.10)
Requirement already satisfied: chardet<4,>=3.0.2 in /usr/local/lib/python3.6/dist-packages (from requests>=2.20.0->neptune-client) (3.0.4)
Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.6/dist-packages (from requests>=2.20.0->neptune-client) (2020.6.20)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /usr/local/lib/python3.6/dist-packages (from requests>=2.20.0->neptune-client) (1.24.3)
Collecting gitdb<5,>=4.0.1
Downloading https://files.pythonhosted.org/packages/48/11/d1800bca0a3bae820b84b7d813ad1eff15a48a64caea9c823fc8c1b119e8/gitdb-4.0.5-py3-none-any.whl (63kB)
|████████████████████████████████| 71kB 7.6MB/s
Requirement already satisfied: pyparsing>=2.0.2 in /usr/local/lib/python3.6/dist-packages (from packaging->neptune-client) (2.4.7)
Collecting swagger-spec-validator>=2.0.1
Downloading https://files.pythonhosted.org/packages/09/de/e78cefbf5838b434b63a789264b79821cb2267f1498fbed23ef8590133e4/swagger_spec_validator-2.7.3-py2.py3-none-any.whl
Collecting jsonref
Downloading https://files.pythonhosted.org/packages/07/92/f8e4ac824b14af77e613984e480fa818397c72d4141fc466decb26752749/jsonref-0.2-py3-none-any.whl
Requirement already satisfied: jsonschema[format]>=2.5.1 in /usr/local/lib/python3.6/dist-packages (from bravado-core>=5.16.1->bravado->neptune-client) (2.6.0)
Requirement already satisfied: msgpack>=0.5.2 in /usr/local/lib/python3.6/dist-packages (from bravado-core>=5.16.1->bravado->neptune-client) (1.0.0)
Collecting smmap<4,>=3.0.1
Downloading https://files.pythonhosted.org/packages/b0/9a/4d409a6234eb940e6a78dfdfc66156e7522262f5f2fecca07dc55915952d/smmap-3.0.4-py2.py3-none-any.whl
Collecting rfc3987; extra == "format"
Downloading https://files.pythonhosted.org/packages/65/d4/f7407c3d15d5ac779c3dd34fbbc6ea2090f77bd7dd12f207ccf881551208/rfc3987-1.3.8-py2.py3-none-any.whl
Collecting strict-rfc3339; extra == "format"
Downloading https://files.pythonhosted.org/packages/56/e4/879ef1dbd6ddea1c77c0078cd59b503368b0456bcca7d063a870ca2119d3/strict-rfc3339-0.7.tar.gz
Collecting webcolors; extra == "format"
Downloading https://files.pythonhosted.org/packages/12/05/3350559de9714b202e443a9e6312937341bd5f79f4e4f625744295e7dd17/webcolors-1.11.1-py3-none-any.whl
Building wheels for collected packages: neptune-client, future, msgpack-python, strict-rfc3339
Building wheel for neptune-client (setup.py) ... done
Created wheel for neptune-client: filename=neptune_client-0.4.119-py2.py3-none-any.whl size=150019 sha256=7c9c64b7ed22ecb87295a99202b7b083ae89b821da3d2d7d9575ba2ccde3845f
Stored in directory: /root/.cache/pip/wheels/84/5c/c1/a81e80761b94b4467fd3fda1fd3109463702f6247fc422eb33
Building wheel for future (setup.py) ... done
Created wheel for future: filename=future-0.18.2-cp36-none-any.whl size=491057 sha256=e673765dc114ef0e4bcc1f3e7a4d94ffd1180f5567bd67961e41f87852ff8344
Stored in directory: /root/.cache/pip/wheels/8b/99/a0/81daf51dcd359a9377b110a8a886b3895921802d2fc1b2397e
Building wheel for msgpack-python (setup.py) ... done
Created wheel for msgpack-python: filename=msgpack_python-0.5.6-cp36-cp36m-linux_x86_64.whl size=304255 sha256=7638ccc06f11990a766e1e10c1e2bac10f444af7da1cd8f7a7720c70ac588d72
Stored in directory: /root/.cache/pip/wheels/d5/de/86/7fa56fda12511be47ea0808f3502bc879df4e63ab168ec0406
Building wheel for strict-rfc3339 (setup.py) ... done
Created wheel for strict-rfc3339: filename=strict_rfc3339-0.7-cp36-none-any.whl size=18120 sha256=ce5d2cafd47caca5ee36d7d644a4a9d9f0a43a2b14f5292fddcf1428923f86e7
Stored in directory: /root/.cache/pip/wheels/bb/af/c9/b6e9fb5f9b2470e4ed2a7241c9ab3a8cdd3bc8555ae02ca2e6
Successfully built neptune-client future msgpack-python strict-rfc3339
Installing collected packages: msgpack-python, swagger-spec-validator, simplejson, jsonref, bravado-core, monotonic, bravado, future, xmltodict, py3nvml, PyJWT, websocket-client, smmap, gitdb, GitPython, neptune-client, rfc3987, strict-rfc3339, webcolors
Found existing installation: future 0.16.0
Uninstalling future-0.16.0:
Successfully uninstalled future-0.16.0
Successfully installed GitPython-3.1.7 PyJWT-1.7.1 bravado-10.6.2 bravado-core-5.17.0 future-0.18.2 gitdb-4.0.5 jsonref-0.2 monotonic-1.5 msgpack-python-0.5.6 neptune-client-0.4.119 py3nvml-0.2.6 rfc3987-1.3.8 simplejson-3.17.2 smmap-3.0.4 strict-rfc3339-0.7 swagger-spec-validator-2.7.3 webcolors-1.11.1 websocket-client-0.57.0 xmltodict-0.12.0