m.amintoosi @ hsu.ac.ir
زمستان ۱۴۰۰
These Slides are accessible from my github page
or by scanning this QR Code: Program Codes: https://github.com/mamintoosi-cs/pytorch-workshop |
حوزهی یادگیری عمیق زیرمجموعهای از روشهای یادگیری ماشین است که توجه بسیاری را در چند سال اخیر
به خود معطوف نموده است. تفاوت اصلی یادگیری عمیق با روشهای مرسوم حوزهی یادگیری ماشین، توانایی
آن در یادگیری خودکار ویژگیها است. هستهی اصلی یادگیری در این روشها مبتنی بر الگوریتم گرادیان
کاهشی و بخش عملی آن متکی بر توانایی مشتقگیری خودکار ازتوابع هدف است. در این کارگاه به معرفی
مبانی نظری این حوزه و برخی کاربردهای آن پرداخته شده و شیوهی شروع به کار عملی در این حوزه با
انجام برنامهنویسی در زبان پایتون بیان خواهد شد.
منابع زیر میتواند برای شروع یادگیری و آشنایی با یادگیری عمیق مثمرثمر واقع گردند:
Some good, some not-so-good
DALL·E is a 12-billion parameter version of GPT-3 trained to generate images from text descriptions, using a dataset of text–image pairs
Artist Salvador Dalí and Pixar’s WALL·E.
DALL·E is a 12-billion parameter version of GPT-3 trained to generate images from text descriptions, using a dataset of text–image pairs
The holistic approaches dominated the face recognition community in the 1990s. In the early 2000s, handcrafted local descriptors became popular, and the local feature learning approach were introduced in the late 2000s. […] [shallow learning method] performance steadily improves from around 60% to above 90%, while deep learning boosts the performance to 99.80% in just three years.Example DeepFace github page Detection, Localization, Verification, Gender, Expression, Age, RealTime, Liveness, Masked, Noise, Partial, ...
It is well established that training deep neural networks gives useful representations that capture essential features of the inputs.Every two points on the same manifold, map to (approximately) the same representation (i.e., the penultimate layer feature map), while every two points from different manifolds go to far away representations.
How Computer see the above picture?
Hinton (Toronto) | ||
LeCun (NYC) | ||
Universities | Bengio (Montreal) | |
Baidu | Ng (Stanford) |
“AI is the new electricity.”
In general, three technical forces are driving advances:
We will discuss:
Python Data Science Handbook. Essential Tools for Working with Data by: Jake VanderPlas |
Don’t confuse a 5D vector with a 5D tensor! A 5D vector has only one axis and has five dimensions along its axis, whereas a 5D tensor has five axes (and may have any number of dimensions along each axis).
Dimensionality can denote either the number of entries along a specific axis (as in the case of our 5D vector) or the number of axes in a tensor (such as a 5D tensor), which can be confusing at times. In the latter case, it’s technically more correct to talk about a tensor of rank 5 (the rank of a tensor being the number of axes), but the ambiguous notation 5D tensor is common regardless.
See 1_Basics.ipynb
in
github
my_slice = train_images[:, 14:, 14:]
batch = train_images[128 * n:128 * (n + 1)]
(samples, features)
(samples, timesteps, features)
(samples, height, width, channels) or
(samples, channels, height, width)
(samples, frames, height, width, channels) or
(samples, frames, channels, height, width)
See 2_Autograd.ipynb
in
github
from torch import autograd
x = torch.Tensor([4])
x.requires_grad_()
y = torch.Tensor([0])
y.requires_grad_()
f = 5 * x**2 + 3*torch.sin(y)
df_dx = autograd.grad(f, x)[0]
print("∂f/∂x| x=4 :", df_dx.item())
df_dy = autograd.grad(f, y)[0]
print("∂f/∂y| y=0 :", df_dy.item())
∂f/∂x| x=4 : 40.0
∂f/∂y| y=0 : 3.0
See 3_Regression_Gradient_Descent.ipynb
in
github
for epoch in range(num_epochs):
y_hat = b + w * xTrain
error = (y_hat - yTrain)
loss = (error ** 2).mean()
loss.backward()
with torch.no_grad():
b -= lr * b.grad
w -= lr * w.grad
b.grad = None
w.grad = None
See 4_MLP_Digit_Classification.ipynb
in
github
class MyMultilayerPerceptron(nn.Module):
def __init__(self, input_size, h_dim, num_classes):
super(MyMultilayerPerceptron, self).__init__()
self.input_size = input_size
self.num_classes = num_classes
self.linear_1 = nn.Linear(input_size, h_dim)
self.linear_2 = nn.Linear(h_dim, num_classes)
def forward(self, x):
x = F.relu(self.linear_1(x))
x = F.relu(self.linear_2(x))
return F.softmax(x)
# model is a regression or classification
optimizer = torch.optim.SGD(model.parameters(), lr=1e-3)
for epoch in range(num_epochs):
for (inputs, labels) in data_loader:
# Do Forward -> Loss Computation -> Backward -> Optimization
optimizer.zero_grad()
outputs = model(inputs)
# loss is prediction error, such as: Sum(outputs-labels)^2
loss.backward()
optimizer.step()
Introduction to convnets
-1 | 0 | +1 |
-1 | 0 | +1 |
-1 | 0 | +1 |
See App_Image.ipynb
in
github
See App_Image.ipynb
in
github
See 5_CNN_CIFAR.ipynb
in
github
import torch.nn as nn
import torch.nn.functional as F
class Net(nn.Module):
def __init__(self):
super().__init__()
self.conv1 = nn.Conv2d(3, 6, 5)
self.pool = nn.MaxPool2d(2, 2)
self.conv2 = nn.Conv2d(6, 16, 5)
self.fc1 = nn.Linear(16 * 5 * 5, 120)
self.fc2 = nn.Linear(120, 84)
self.fc3 = nn.Linear(84, 10)
def forward(self, x):
x = self.pool(F.relu(self.conv1(x)))
x = self.pool(F.relu(self.conv2(x)))
x = torch.flatten(x, 1) # flatten all dimensions except batch
x = F.relu(self.fc1(x))
x = F.relu(self.fc2(x))
x = self.fc3(x)
return x
model = Net()
See 5_CNN_CIFAR.ipynb
in
github
for (inputs, labels) in data_loader:
inputs = inputs.to(device)
labels = labels.to(device)
# original shape is [batch_size, 28, 28] because it's an image of size 28x28
inputs = inputs.view(-1, 28*28)
# Do Forward -> Loss Computation -> Backward -> Optimization
optimizer.zero_grad()
outputs = model(inputs)
loss = criterion(outputs, labels)
loss.backward()
optimizer.step()
“Data is food for AI”He simply means that without data, the model is useless. You must have good quality, well cleansed data in order to produce a high quality model.
“The model and the code for many applications are basically a solved problem”
This isn't to say that you shouldn't pick the best algorithm for the job. As we have already seen picking a good algorithm makes a significant difference. However, if you are trying to solve a practical problem (rather than publish a research paper) it might not be worth your while to spend a lot of time researching and tweaking algorithms. You will perhaps get more bang for your buck—or a better return on your time—if you concentrate on getting more data.Source: A Programmer's Guide to Data Mining
Mike has Bachelor of Science degrees in Business and Psychology. He started his career as a middle school psychologist prior to moving into the information technology space. His love of computers resulted in him spending many additional hours working on computers while studying for his master's degree in Statistics. His current areas of interests include Machine Learning, Data Engineering and SQL Server. |
Mike West |
webpage : http://mamintoosi.ir
webpage in github : http://mamintoosi.github.io
github : mamintoosi