- A set is an unordered collection of unique elements. Examples are natural numbers, integers, rational numbers, and real numbers
- Cartesian product of
$A$ and$B$ is$A \times B = \lbrace(a, b) : a \in A, b \in B\rbrace$ - A function from set
$A$ to set$B$ is a rule of correspondence that assigns each element$x \in A$ to uniquely determined element$f(x) \in B$ - Set
$A$ is called the domain of$f$ - Set
$B$ is the codomain of$f$ - The set
$f(A) = \lbrace(x) : x \in A\rbrace$ is called the range of$f$ - Althought
$D(f) = A$ , we only have$R(f) \subseteq B$
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
import torch | |
import torch.nn as nn | |
import torch.nn.functional as F | |
""" | |
Creating tensors | |
""" | |
a = torch.rand(...) # returns a torch.Tensor | |
b = torch.LongTensor(10).random_(0, 2) # 10-dim vector from [0, 1] |
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
import os | |
import numpy as np | |
import random | |
import tensorflow as tf | |
from tfdeterminism import patch | |
def seed(s=42): | |
random.seed(s) | |
np.random.seed(s) | |
tf.random.set_seed(s) |
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
import torch | |
import torch.nn as nn | |
import torch.nn.functional as F | |
from torchvision import transforms | |
import numpy as np | |
from PIL import Image | |
import matplotlib.pyplot as plt | |
from patchify import patchify, unpatchify # pip install patchify |
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
!wget http://www.some_dataset_website.com/my_dataset.tar.gz | |
!tar -xvzf my_dataset.tar.gz |
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
PATH = "./my_dataset/" # path to dataset on Colab instance | |
TRAIN_PATH = PATH + "train/" | |
VAL_PATH = PATH + "val/" | |
# your custom augmentations | |
T = transforms.Compose([ | |
transforms.ToTensor(), | |
... | |
]) |
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
''' | |
Configures some pipeline hyper-parameters. You | |
can set them to whatever you please. | |
You have the option of either mentioning it here | |
or creating variables inside the map_fn function. | |
This is entirely up to you. I do both for demonstration purposes. | |
''' |
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
# hlper function to get the testing accuracy at the end of the epoch | |
def get_test_stats(model, loader): | |
total_samples = 0 | |
correct = 0 | |
model.eval() # switch to eval mode | |
for (batch_idx, data) in enumerate(loader, 0): | |
x, y = data | |
logits = model(x) | |
preds = torch.argmax(logits, 1) |
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
device = xm.xla_device() | |
# define some hyper-params you'd feed into your model | |
in_channels = ... | |
random_param = ... | |
# create model using appropriate hyper-params | |
net = MyCustomNet(...) | |
# seat it atop the TPU worker device and switch it to train mode |
NewerOlder