https://jupyter.org
Hours Score
10 90
9 80
3 50
2 30
(“ ” – ” ”)&
Model	1	𝐻( 𝑥 = 6.6𝑥 + 22.9
Model	2	𝐻& 𝑥 = 5.5𝑥 + 34.5
Model	3	𝐻3 𝑥 = 8.25𝑥 + 23
𝐱 𝐲 𝐇 𝟏 𝐱 (𝐇 𝟏 𝐱 − 𝐲) 𝟐
𝐇 𝟐 𝐱 (𝐇 𝟐 𝐱 − 𝐲) 𝟐
𝐇 𝟑 𝐱 (𝐇 𝟑 𝐱 − 𝐲) 𝟐
0
20
40
60
80
100
0 5 10 15
𝐇 𝐱 = 𝐚𝐱 + 𝐛
𝐇 𝐱 = 𝐰 𝟏×𝐱 + 𝐰 𝟎×𝟏
𝐖 = 𝐰 𝟏 𝐰 𝟎 𝐗 =
𝐱
𝟏
𝐇 𝐱 = 𝐖𝐗
𝐖
𝐖
𝛁𝐋𝐨𝐬𝐬
𝐋𝐨𝐬𝐬 𝐰
𝛂
𝐰
𝐖
𝟏
𝐦
∑𝐢K𝟏
𝐦
𝐖×𝐗 𝐢 − 𝐲 𝐢 𝟐
(예측 값 – 실제 값)&
𝐇 𝐱 = 𝐖𝐗
𝐦𝐢𝐧𝐢𝐦𝐢𝐳𝐞 𝑳𝒐𝒔𝒔 𝐰
𝐖
!"#$$
"#$$ %
&
%	
𝛁𝐋𝐨𝐬𝐬
𝐖 = 𝐖 − 𝛂𝛁𝐋𝐨𝐬𝐬
𝝈 𝒙 = 𝑠𝑖𝑔𝑚𝑜𝑖𝑑 𝑥 =
1
1 + e]
𝐇 𝒙 = 𝐚𝐜𝐭𝐢𝐯𝐚𝐭𝐢𝐨𝐧_𝐟𝐧(𝒘 𝟎 + 𝒘 𝟏 𝒙 𝟏 + ⋯ + 𝒘 𝒏 𝒙 𝒏)
𝑥f
bias(wl)
𝐻 𝑥
𝑥(
𝚺 𝝈
𝑥&
𝝈 𝒙 = 𝑟𝑒𝑙𝑢 𝑥 = r
𝑥 = 0 (𝑥 < 0)
𝑥 = 𝑥 (𝑥 ≥ 0)
𝐇 𝒙 = 𝐬𝐢𝐠𝐦𝐨𝐢𝐝 (𝒘 𝟎 + 𝒘 𝟏 𝒙 𝟏 + ⋯ + 𝒘 𝒏 𝒙 𝒏) =
𝟏
𝟏 + 𝐞(∑ 𝒘 𝒊 𝒙 𝒊)
𝑥f
w(
bias(wl)
H 𝑥𝚺 𝝈
𝝈 𝒙 = 𝑠𝑖𝑔𝑚𝑜𝑖𝑑 𝑥 =
1
1 + e]
𝑥(
𝑤f
𝑥( 𝑥&
𝑥f
𝑥&
𝑥f
w(
bias(wl)
H 𝑥𝚺 𝝈
𝑥(
𝑤f
class	MyModel(torch.nn.Module):				
def __init__(self):								
super(MyScoreModel,	self).__init__()
self.weights =	torch.nn.Parameter(torch.randn(n))
self.bias =	torch.nn.Parameter(torch.randn(1))
self.activation_fn	=	torch.nn.Sigmoid()
def forward(self,	x):
output	=	self.weights *	x	+	self.bias
output	=	self.activation_fn(output)
return	output
𝑥f
bias
𝐻( 𝑥
𝑥(
class	MyModel(torch.nn.Module):				
def __init__(self,	input_num=n,	output_num=1):								
super(MyScoreModel,	self).__init__()
self.linear =	torch.nn.Linear(in_features=n,	
out_features=1,	
bias	=	True)
self.activation_fn	=	torch.nn.Sigmoid()
def forward(self,	x):
output	=	self.linear(x)
output	=	self.activation_fn(output)
return	output
𝑥{
𝑥3
𝑥&
𝑥(
Weights
𝑦&
𝑦(
Weights
•
•
•
•
•
𝑥f
𝑥(
Weights
𝑦&
𝑦(
Weights
Weights
𝑥f
𝑥(
Weights
𝑦&
𝑦(
Weights
Weights
class	MyModel(torch.nn.Module):				
def __init__(self):								
super(MyScoreModel,	self).__init__()
self.linear1	=	torch.nn.Linear(in_features=n,	
out_features =m)
self.linear2	=	torch.nn.Linear(in_features=m,	
out_features =p)
self.linear3	=	torch.nn.Linear(in_features=p,	
out_features =2)
self.activation_fn	=	torch.nn.Sigmoid()
def forward(self,	x):
output	=	self.activation_fn(self.linear1(x))
output	=	self.activation_fn(self.linear2(output))
output	=	self.linear3(output)
return	output
𝑜((
𝑜(•
𝑜&(
𝑜&‚
𝑥&
𝑥(
𝑥3ƒ
outl
out(
out†††
𝑥&
𝑥(
𝑥3ƒ
𝑥&
𝑥(
𝑥ƒ‡‡3ƒ
outl
out(
out†††
𝑥&
𝑥(
𝑥3ƒ
𝑂(ƒ
outl
out(
out†††
𝑂((
𝑂(ƒ
𝑂((𝑤(
𝑤{𝑤‡
𝑤‰
𝑤3&
𝑤3ƒ
𝑥&
𝑥(
𝑥3ƒ
𝑤(
𝑤&(ƒ
outl
out(
out†††
𝑂(ƒ
𝑂((
𝑤(
𝑤{𝑤(
𝑤{
𝑤(
𝑤{
𝑥&
𝑥(
𝑥3ƒ
𝑤(
𝑤{
𝑤(
𝑤{
𝝈
𝑤(
𝑤{
𝑤(
𝑤{
𝝈
𝑤( 𝑤&
𝑤3 𝑤{
𝝈
class ConvModel(torch.nn.Module):
def __init__(self):
super().__init__()
self.conv1	= torch.nn.Conv2d(in_channels=1, out_channels=16,
kernel_size=3)
self.pool =	torch.nn.MaxPool2d(kernel_size=2)
self.conv2	=	torch.nn.Conv2d(in_channels=16, out_channels=32,
kernel_size=3)
self.fc1	= torch.nn.Linear(in_features=11*11*32, out_features=128)
self.fc2	= torch.nn.Linear(in_features=128, out_features=10)
self.relu = torch.nn.ReLU()
def forward(self, x):
x =	self.conv1(x)
x = self.relu(x)
x = self.pool(x)
x =	self.conv2(x)
x = self.relu(x)
x = x.view(x.shape[0], -1)
x =	self.fc1(x)
x = self.relu(x)
x.	= self.fc2(x)
return x
https://github.com/karansikka1/iFood_2019
ImageNet Food Dataset
0
0
0
class	FoodDataset(torch.utils.data.Dataset):
def __init__(self,	datafile):	
self.samples =	[]
lines	=	open(datafile).read().splitlines()
for	line	in	lines:
path,	label	=	line.split(‘:’)
self.samples.append((path,	label))
def __getitem__(self,	idx):
path,	label	=	self.samples[idx]
image	=	cv2.imread(path)
...
return	image,	float(label)
def __len__(self):
return	len(self.samples)
train_dataset =	FoodDataset('dataset/data.list’)
train_loader =	torch.utils.data.DataLoader(dataset=train_dataset,	batch_size=batch_size,	shuffle=True)
image_converter =	transforms.ToPILImage()
for	images,	labels	in	train_loader:				
label	=	str(labels[0].numpy())				
image	=	image_converter(images[0])			
print	(label,	id_to_names[label])				
plt.imshow(image)
plt.show()
fc1000
import	torchvision.models as	models
class	FoodModel(torch.nn.Module):				
def __init__(self):
super().__init__()
self.model =	models.resnet18(pretrained=True)	
self.model.fc =	torch.nn.Linear(512,	20)
def forward(self,	x):
return	self.model(x)
딥러닝, 야 너도 할 수 있어(feat. PyTorch)
딥러닝, 야 너도 할 수 있어(feat. PyTorch)
딥러닝, 야 너도 할 수 있어(feat. PyTorch)
딥러닝, 야 너도 할 수 있어(feat. PyTorch)

딥러닝, 야 너도 할 수 있어(feat. PyTorch)