This repository has been archived by the owner on Oct 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 244
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
3,333 additions
and
2,185 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
is_ready = True | ||
installed_packages = [] | ||
uninstalled_packages = [] | ||
try: | ||
import torch | ||
installed_packages.append("파이토치 버전:%s" % torch.__version__) | ||
except: | ||
is_ready = False | ||
uninstalled_packages.append("파이토치") | ||
try: | ||
import torchvision | ||
installed_packages.append("토치비젼 버전:%s" % torchvision.__version__) | ||
except: | ||
is_ready = False | ||
uninstalled_packages.append("토치비전") | ||
try: | ||
import torchtext | ||
installed_packages.append("토치텍스트 버전:%s" % torchtext.__version__) | ||
except: | ||
is_ready = False | ||
uninstalled_packages.append("토치텍스트") | ||
try: | ||
import numpy | ||
installed_packages.append("넘파이 버전:%s" % numpy.__version__) | ||
except: | ||
is_ready = False | ||
uninstalled_packages.append("넘파이") | ||
try: | ||
import matplotlib | ||
installed_packages.append("맷플랏립 버전:%s" % matplotlib.__version__) | ||
except: | ||
is_ready = False | ||
uninstalled_packages.append("맷플랏립") | ||
try: | ||
import sklearn | ||
installed_packages.append("사이킷런 버전:%s" % sklearn.__version__) | ||
except: | ||
is_ready = False | ||
uninstalled_packages.append("사이킷런") | ||
|
||
if is_ready: | ||
print("축하합니다! 3분 딥러닝 파이토치맛 예제 실행을 위한 환경설정이 끝났습니다.") | ||
print("설치된 라이브러리 정보:") | ||
for pkg in installed_packages: | ||
print(" * " + pkg) | ||
else: | ||
print("미설치된 라이브러리가 있습니다.") | ||
print("설치된 라이브러리 정보:") | ||
for pkg in installed_packages: | ||
print(" * " + pkg) | ||
print("미설치된 라이브러리 정보:") | ||
for pkg in uninstalled_packages: | ||
print(" * " + pkg) | ||
|
32 changes: 0 additions & 32 deletions
32
02-Getting-Started-With-PyTorch/torchvision-and-torchtext.ipynb
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
178 changes: 58 additions & 120 deletions
178
03-Coding-Neural-Networks-In-PyTorch/00-image-recovery.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#!/usr/bin/env python | ||
# coding: utf-8 | ||
|
||
# ## 프로젝트 1. 경사 하강법으로 이미지 복원하기 | ||
# ### 프로젝트 개요와 목표 | ||
# 이번 프로젝트에서 우리가 풀 문제는 다음과 같습니다. | ||
# 치명적인 버그가 있는 weird_function() 이라는 함수가 original_image 라고 하는 어느 이미지 파일을 입력받아 broken_image 라는 이미지를 리턴했습니다. 우리는 이 오염된 이미지를 삭제하려고 했으나 실수로 원본 이미지 파일을 삭제해버린 상황입니다. | ||
# 다행히도 weird_function()의 소스코드는 삭제되지 않았습니다. | ||
# 우리의 목표는 오염된 이미지와 weird_function()의 코드만을 가지고 원본 이미지 파일을 복원하는 것입니다. | ||
# *Sources are based on https://github.com/jcjohnson/pytorch-examples, NYU Intro2ML* | ||
|
||
get_ipython().run_line_magic('matplotlib', 'inline') | ||
import torch | ||
import pickle | ||
import matplotlib.pyplot as plot | ||
|
||
|
||
shp_original_img = (100, 100) | ||
broken_image = torch.FloatTensor( pickle.load(open('./broken_image_t.p', 'rb'),encoding='latin1' ) ) | ||
|
||
|
||
plot.imshow( broken_image.view(100,100) ) | ||
|
||
|
||
def weird_function(x, n_iter=5): | ||
h = x | ||
filt = torch.tensor([-1./3, 1./3, -1./3]) | ||
for ii in range(n_iter): | ||
zero_tensor = torch.tensor([1.0*0]) | ||
h_l = torch.cat( (zero_tensor, h[:-1]), 0) | ||
h_r = torch.cat((h[1:], zero_tensor), 0 ) | ||
h = filt[0] * h + filt[2] * h_l + filt[1] * h_r | ||
if ii % 2 == 0: | ||
h = torch.cat( (h[h.shape[0]//2:],h[:h.shape[0]//2]), 0 ) | ||
return h | ||
|
||
|
||
def distance_loss(hypothesis, broken_image): | ||
return torch.dist(hypothesis, broken_image, 2) | ||
|
||
|
||
random_tensor = torch.randn(10000, dtype = torch.float) | ||
print(random_tensor) | ||
print(weird_function(random_tensor)) | ||
|
||
|
||
lr = 0.8 | ||
for i in range(0,20000): | ||
random_tensor.requires_grad_(True) | ||
hypothesis = weird_function(random_tensor) | ||
loss = distance_loss(hypothesis, broken_image) | ||
loss.backward() | ||
with torch.no_grad(): | ||
random_tensor = random_tensor - lr*random_tensor.grad | ||
if i % 1000 == 0: | ||
print('Loss at ', i, ' = ', loss.item()) | ||
|
||
|
||
plot.imshow( random_tensor.view(100,100).data ) | ||
|
||
|
||
plot.imshow( random_tensor.view(100,100).data,cmap = 'gray') | ||
|
Oops, something went wrong.