Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
778 changes: 778 additions & 0 deletions ML-lectures/0.ipynb

Large diffs are not rendered by default.

907 changes: 907 additions & 0 deletions ML-lectures/1.ipynb

Large diffs are not rendered by default.

793 changes: 793 additions & 0 deletions ML-lectures/img/hard/Recurrent_neural_network_unfold.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ML-lectures/img/hard/alexnet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ML-lectures/img/hard/confusion.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ML-lectures/img/hard/convolution.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ML-lectures/img/hard/convolution_encoder.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ML-lectures/img/hard/decision_tree.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ML-lectures/img/hard/feedforward.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ML-lectures/img/hard/gan.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ML-lectures/img/hard/image-segmentation.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ML-lectures/img/hard/imagenet-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ML-lectures/img/hard/imagenet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ML-lectures/img/hard/knearest.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ML-lectures/img/hard/object-dectection.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ML-lectures/img/hard/segnet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ML-lectures/img/hard/transfer-learning.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ML-lectures/img/hard/u-net.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ML-lectures/img/hard/vgg16.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ML-lectures/img/hard/vgg16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ML-lectures/img/hard/yolo.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ML-lectures/img/soft/DL.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ML-lectures/img/soft/boosting.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ML-lectures/img/soft/supervised-2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ML-lectures/img/soft/supervised.jpg
Binary file added ML-lectures/img/soft/to-be-continued.png
Binary file added ML-lectures/img/soft/tree.png
Binary file added ML-lectures/img/soft/unsupervised.webp
Binary file added ML-lectures/img/soft/wanted-ds.png
45 changes: 45 additions & 0 deletions ML-lectures/magic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import torch
import numpy as np
from matplotlib import pyplot as plt
import matplotlib
import sys

matplotlib.rcParams['figure.dpi'] = 160

# You need to clone https://github.com/NVlabs/stylegan3
sys.path.append('./stylegan3/') # because of very strange way to deserialize stylegan
import importlib.abc # fix import abc error

import dnnlib
import legacy

PET_MODEL = 'https://api.ngc.nvidia.com/v2/models/nvidia/research/stylegan3/versions/1/files/stylegan3-r-afhqv2-512x512.pkl'
HUMAN_MODEL = 'https://api.ngc.nvidia.com/v2/models/nvidia/research/stylegan3/versions/1/files/stylegan3-r-ffhq-1024x1024.pkl'


def generate_img(model, seed=None, truncation_psi=1, noise_mode='const'):
seed = seed or np.random.randint(0, np.iinfo(np.int32).max)
print('Loading networks from "%s"...' % model)
device = torch.device('cuda')
with dnnlib.util.open_url(model) as f:
G = legacy.load_network_pkl(f)['G_ema'].to(device)

# Labels.
label = torch.zeros([1, G.c_dim], device=device)

# Generate images.
print(f'Generating image for seed {seed} ...')
z = torch.from_numpy(np.random.RandomState(seed).randn(1, G.z_dim)).to(device)


img = G(z, label, truncation_psi=truncation_psi, noise_mode=noise_mode)
img = (img.permute(0, 2, 3, 1) * 127.5 + 128).clamp(0, 255).to(torch.uint8)
return img[0].cpu().numpy()


def generate_pet(seed=None):
return generate_img(PET_MODEL, seed)


def generate_human(seed=None):
return generate_img(HUMAN_MODEL, seed)
58 changes: 58 additions & 0 deletions ML-lectures/prelude.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import numpy as np
import matplotlib
import scipy.interpolate
import torch

from numpy.polynomial.polynomial import Polynomial
from matplotlib import pyplot as plt
from torch import optim
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression, LinearRegression
from sklearn.preprocessing import PolynomialFeatures
from sklearn.cluster import KMeans
from sklearn.ensemble import GradientBoostingClassifier
from sklearn.tree import DecisionTreeClassifier
from sklearn.neighbors import KNeighborsClassifier
from sklearn.tree import plot_tree


matplotlib.rcParams.update({'axes.grid' : True})
# matplotlib.rcParams['figure.figsize'] = [12, 8]
matplotlib.rcParams['figure.dpi'] = 160


def random_points(size: int = 10):
x = np.linspace(0, 1, size)
y = np.sin(x*10) + x * 3 + np.random.randn(size) * 0.3
return np.stack([x, y])


def f(x, params):
return sum(
k * x**i
for i, k in enumerate(params)
)


def lagrange(x, y):
poly = scipy.interpolate.lagrange(x, y)
# looks too weird https://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.lagrange.html
return Polynomial(poly.coef[::-1]).coef


def cluster(mean, sigma=np.identity(2), count=100):
return np.random.randn(count, 2) @ sigma + mean


def plot_decision_boundary(model, X, Y, h=0.02, margin=1, cmap='Paired_r'):
x_min, x_max = X[:,0].min() - margin, X[:,0].max() + margin
y_min, y_max = X[:,1].min() - margin, X[:,1].max() + margin
xx, yy = np.meshgrid(
np.arange(x_min, x_max, h), np.arange(y_min, y_max, h)
)
Z = model.predict(np.c_[xx.ravel(), yy.ravel()])
Z = Z.reshape(xx.shape)

plt.contourf(xx, yy, Z, cmap=cmap, alpha=0.55)
plt.contour(xx, yy, Z, colors='k', linewidths=0.7)
plt.scatter(X[:,0], X[:,1], c=Y, cmap=cmap, edgecolors='k');
7 changes: 7 additions & 0 deletions ML-lectures/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
matplotlib==3.5.1
numpy==1.22.3
scikit_learn==1.0.2
scipy==1.8.0
torch==1.11.0
tqdm==4.63.2
tensorflow==2.8.0