Skip to content
This repository has been archived by the owner on Oct 19, 2023. It is now read-only.

Commit

Permalink
recompile python
Browse files Browse the repository at this point in the history
  • Loading branch information
keon committed Jul 14, 2019
1 parent 49739df commit 8855eda
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 710 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import torch
import torch.nn as nn
import torch.nn.functional as F
import random

get_ipython().run_line_magic('matplotlib', 'inline')

Expand Down Expand Up @@ -51,18 +52,15 @@ def forward(self, inputs, targets):

# 디코더 (Decoder)
outputs = []
for i in range(targets.size()[0]):

for i in range(targets.size()[0]):
decoder_input = self.embedding(decoder_input)
decoder_output, decoder_state = self.decoder(decoder_input, decoder_state)
projection = self.project(decoder_output)
outputs.append(projection)

# 디코더의 출력값으로 다음 글자 예측하기
projection = self.project(decoder_output.view(1, -1)) # batch x vocab_size
prediction = F.softmax(projection, dim=1) # batch x vocab_size
outputs.append(prediction)

# 디코더 입력 갱신
_, top_i = prediction.data.topk(1) # 1 x 1
decoder_input = top_i
#티처 포싱(Teacher Forcing) 사용
decoder_input = torch.LongTensor([[targets[i]]])

outputs = torch.stack(outputs).squeeze()
return outputs
Expand Down
112 changes: 0 additions & 112 deletions 07-순차적인_데이터를_처리하는_RNN/03-seq2seq_gru.py

This file was deleted.

Binary file not shown.
1 change: 0 additions & 1 deletion 07-순차적인_데이터를_처리하는_RNN/assets/pics

This file was deleted.

14 changes: 7 additions & 7 deletions 08-딥러닝_해킹하기/01-fgsm-attack.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@

CLASSES = json.load(open('./imagenet_samples/imagenet_classes.json'))
idx2class = [CLASSES[str(i)] for i in range(1000)]
class2idx = {v:i for i,v in enumerate(idx2class)}


# ## 이미지 불러오기
Expand All @@ -53,8 +52,8 @@


# 시각화를 위해 넘파이 행렬 변환
original_img_view = img_tensor.squeeze(0) # [1, 3, 244, 244] -> [3, 244, 244]
original_img_view = original_img_view.transpose(0,2).transpose(0,1).detach().numpy()
original_img_view = img_tensor.squeeze(0).detach() # [1, 3, 244, 244] -> [3, 244, 244]
original_img_view = original_img_view.transpose(0,2).transpose(0,1).numpy()

# 텐서 시각화
plt.imshow(original_img_view)
Expand Down Expand Up @@ -86,7 +85,7 @@ def fgsm_attack(image, epsilon, gradient):
# ## 적대적 예제 생성

# 이미지의 기울기값을 구하도록 설정
img_tensor.requires_grad = True
img_tensor.requires_grad_(True)

# 이미지를 모델에 통과시킴
output = model(img_tensor)
Expand Down Expand Up @@ -121,7 +120,8 @@ def fgsm_attack(image, epsilon, gradient):


# 시각화를 위해 넘파이 행렬 변환
perturbed_data_view = perturbed_data.squeeze(0).transpose(0,2).transpose(0,1).detach().numpy()
perturbed_data_view = perturbed_data.squeeze(0).detach()
perturbed_data_view = perturbed_data_view.transpose(0,2).transpose(0,1).numpy()

plt.imshow(perturbed_data_view)

Expand All @@ -130,11 +130,11 @@ def fgsm_attack(image, epsilon, gradient):

f, a = plt.subplots(1, 2, figsize=(10, 10))

# 원본 사진
# 원본
a[0].set_title(prediction_name)
a[0].imshow(original_img_view)

# 복원된 사진
# 적대적 예제
a[1].set_title(perturbed_prediction_name)
a[1].imshow(perturbed_data_view)

Expand Down
Loading

0 comments on commit 8855eda

Please sign in to comment.