Last active
November 7, 2023 14:42
-
-
Save prateekgargX/09a20acf348bef9ecb7154035d7561fb to your computer and use it in GitHub Desktop.
a file to paste into jupyter notebook everytime i start a new project. From UvA DL tutorials: https://uvadlc-notebooks.readthedocs.io/en/latest/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Standard libraries | |
import os | |
import json | |
import math | |
import numpy as np | |
## Imports for plotting | |
import matplotlib.pyplot as plt | |
%matplotlib inline | |
import matplotlib_inline | |
matplotlib_inline.backend_inline.set_matplotlib_formats('svg','pdf') # For export | |
from matplotlib.colors import to_rgb | |
import matplotlib | |
matplotlib.rcParams['lines.linewidth'] = 2.0 | |
import seaborn as sns | |
sns.reset_orig() | |
sns.set() | |
## Progress bar | |
from tqdm.notebook import tqdm | |
## PyTorch | |
import torch | |
import torch.nn as nn | |
import torch.nn.functional as F | |
import torch.utils.data as data | |
import torch.optim as optim | |
# Torchvision | |
import torchvision | |
from torchvision.datasets import CIFAR10 | |
from torchvision import transforms | |
# PyTorch Lightning | |
try: | |
import pytorch_lightning as pl | |
except ModuleNotFoundError: # Google Colab does not have PyTorch Lightning installed by default. Hence, we do it here if necessary | |
!pip install --quiet pytorch-lightning>=1.4 | |
import pytorch_lightning as pl | |
from pytorch_lightning.callbacks import LearningRateMonitor, ModelCheckpoint | |
# Path to the folder where the datasets are/should be downloaded (e.g. CIFAR10) | |
DATASET_PATH = | |
# Path to the folder where the pretrained models are saved | |
CHECKPOINT_PATH = | |
# Setting the seed | |
pl.seed_everything(42) | |
# Ensure that all operations are deterministic on GPU (if used) for reproducibility | |
torch.backends.cudnn.deterministic = True | |
torch.backends.cudnn.benchmark = False | |
device = torch.device("cuda:0") if torch.cuda.is_available() else torch.device("cpu") | |
print("Device:", device) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment