DEV Community

4rldur0
4rldur0

Posted on

댑덥딥 8주차 정리

'모두를 위한 딥러닝 시즌 2' 강의를 듣고 공부하는 스터디 입니다. https://deeplearningzerotoall.github.io/season2/lec_tensorflow.html


비대면 31 May, 2023

10-7 next step of CNN

CV 관련 앞으로 할만한 것들

classification: 분류

-DenseNet, SENet, MobileNet, SqueezeNet, AutoML(NAS, NASNet)

object detection: 탐지

-Latest Object Detection을 검색

GitHub logo hoya012 / deep_learning_object_detection

A paper list of object detection using deep learning.

deep learning object detection

A paper list of object detection using deep learning. I wrote this page with reference to this survey paper and searching and searching..

Last updated: 2020/09/22

Update log

2018/9/18 - update all of recent papers and make some diagram about history of object detection using deep learning 2018/9/26 - update codes of papers. (official and unofficial)
2018/october - update 5 papers and performance table.
2018/november - update 9 papers.
2018/december - update 8 papers and and performance table and add new diagram(2019 version!!).
2019/january - update 4 papers and and add commonly used datasets.
2019/february - update 3 papers.
2019/march - update figure and code links.
2019/april - remove author's names and update ICLR 2019 & CVPR 2019 papers.
2019/may - update CVPR 2019 papers.
2019/june - update CVPR 2019 papers and dataset paper.
2019/july - update BMVC 2019 papers and some of ICCV…

object tracking: 프레임 간의 연관관계

-MDNet, GOTURN, CFNet, ROLO, Tracking the Untrackable

segmetation: 배경과 객체 분할

-FCN, U-Net, Mask RCNN

Image Captioning

Super Resolution

Generative Model(AutoEncoder, GAN)

OpenPose

  • [ ] Pytorch가 가지고 있는 다양한 기능들 직접 사용해보기!
  • [ ] Custom DataSet 만드는 방법 익히기
  • [ ] Pytorch가 제공하지 않는 데이터셋을 다운받아서 학습해보기 (Tiny-ImageNet Challenge 추천!)

11-0 RNN intro

RNN? sequential data를 다루기 위해 고안됨. ex) word, sentence, time series

sequential data? 순서가 중요한 data. ex) “hello”를 “elhol”로 바꾸면 알아듣지 못 함

-RNN 이전에도 position index를 활용하여 sequential data를 처리할 수 있었음. 다만, 복잡한 구조 파악 어려웠음

Image description

: A라는 셀에 t번째 입력값이 들어오면, t번째 출력값이 나오고, 동시에 다른 출력값이 셀 A로 들어감. 이때 다른 출력값을 hidden state라고 하며, 다음 셀로 전달됨. 따라서 t+1번째의 출력값은 t번째의 영향을 받음. 다음 셀은 사실 원래의 셀과 같은 것임(=모든 셀 A는 같음. 모두 같은 함수(파라미터)를 공유하기 때문)

Image description

Ht는 기본적으로 w를 인자로 갖는 함수 연산에 의해 나옴. Ht-1은 hidden state이고, y는 Ht와 같음.

ex) (vanilla) recurrent neural network

Image description

caracter-level language model example

Image description

Usages of RNN

Image description

ex)

1) 이미지→이미지에 대한 설명

2) 문장 → 감정 레이블

3) 문장 → 문장 (문장이 다 끝난 시점부터 다음 문장이 나옴)

4) 비디오 → 비디오

multilayered RNN

Image description

RNN applications

Image description

cf) advanced model examples

-LSTM(http://colah.github.io/posts/2015-08-Understanding-LSTMs/)

-GRU

11-1 RNN basics

RNN in PyTorch

rnn = torch.nn.RNN(input_size, hidden_size)
outputs, _status = rnn(input_data)
Enter fullscreen mode Exit fullscreen mode
  • input/output shape: dimension 3짜리 torch tensor

    input shape = (batch size, sequence length, input_size)

    output shape = (batch size, sequence length, hidden_size)

-batch size, sequnece length는 pytorch가 input data에 따라 자동으로 판별함

example_hello를 입력 받았을 때, ello-를 출력받기

import torch
import numpy as np

input_size = 4
hidden_size = 2

# 1-hot encoding
h = [1, 0, 0, 0]
e = [0, 1, 0, 0]
l = [0, 0, 1, 0]
o = [0, 0, 0, 1]
#input_size = 4

input_data_np = np.array([[h, e, l, l, o],
                                                [e, o, l, l, l],
                                                [l, l, e, e, l]], dtype=np.float32)
#batch size = 3

# transform as torch tensor
input_data = torch.Tensor(input_data_np)

rnn = torch.nn.RNN(input_size, hidden_size)
outputs, _status = rnn(input_data)
Enter fullscreen mode Exit fullscreen mode

11-2 RNN hihello and charseq

Hihello problem

h가 들어오면 i를, i가 들어오면 h를, h가 들어오면 e를, … 예측하는 문제

-위의 example과 비슷

##prepare data for hihello problem
char_set = ['h', 'i', 'e', 'l', 'o']
# hyper parameters
input_size = len(char_set)
hidden_size = len(char_set)
learning_rate = 0.1
# data setting
x_data = [[0, 1, 0, 2, 3, 3]]
x_one_hot = [[[1, 0, 0, 0, 0],
[0, 1, 0, 0, 0],
[1, 0, 0, 0, 0],
[0, 0, 1, 0, 0],
[0, 0, 0, 1, 0],
[0, 0, 0, 1, 0]]]
y_data = [[1, 0, 2, 3, 3, 4]]
# transform as torch tensor variable
X = torch.FloatTensor(x_one_hot)
Y = torch.LongTensor(y_data)
Enter fullscreen mode Exit fullscreen mode

charseq

hihello problem에서 입력을 일반화한 것

sample = " if you want you"
# make dictionary
char_set = list(set(sample))
char_dic = {c: i for i, c in enumerate(char_set)}
# hyper parameters
dic_size = len(char_dic)    #=input_size
hidden_size = len(char_dic)
learning_rate = 0.1
# data setting
sample_idx = [char_dic[c] for c in sample]
x_data = [sample_idx[:-1]]
x_one_hot = [np.eye(dic_size)[x] for x in x_data]
y_data = [sample_idx[1:]]
# transform as torch tensor variable
X = torch.FloatTensor(x_one_hot)
Y = torch.LongTensor(y_data)

# declare RNN
rnn = torch.nn.RNN(input_size, hidden_size, batch_first=True) # batch_first guarantees the order of output = (B, S, F)
# loss & optimizer setting
criterion = torch.nn.CrossEntropyLoss()
optimizer = optim.Adam(rnn.parameters(), learning_rate)

# start training
for i in range(100):
    optimizer.zero_grad()
    outputs, _status = rnn(X)
    loss = criterion(outputs.view(-1, input_size), Y.view(-1))
    loss.backward()
    optimizer.step()
    result = outputs.data.numpy().argmax(axis=2)
    result_str = ''.join([char_set[c] for c in np.squeeze(result)])
    print(i, "loss: ", loss.item(), "prediction: ", result, "true Y: ", y_data, "prediction str: ", result_str)
Enter fullscreen mode Exit fullscreen mode

11-3 RNN Long sequence

longseq

-loger dataset를 특정 사이즈로 잘라 사용(=특정 사이즈의 윈도우를 하나씩 옆으로 옮기며 자름)→자른 데이터를 인덱스로 저장→one-hot encoding→torch tensor화

ex)
Image description

# data setting
x_data = []
y_data = []
for i in range(0, len(sentence) - sequence_length):
    x_str = sentence[i:i + sequence_length]
    y_str = sentence[i + 1: i + sequence_length + 1]
    print(i, x_str, '->', y_str)
    x_data.append([char_dic[c] for c in x_str]) # x str to index
    y_data.append([char_dic[c] for c in y_str]) # y str to index

x_one_hot = [np.eye(dic_size)[x] for x in x_data]

# transform as torch tensor variable
X = torch.FloatTensor(x_one_hot)
Y = torch.LongTensor(y_data)

# declare RNN + FC
# (adding FC and stacking RNN)
class Net(torch.nn.Module):
    def __init__(self, input_dim, hidden_dim, layers):
        super(Net, self).__init__()
        self.rnn = torch.nn.RNN(input_dim, hidden_dim, num_layers=layers, batch_first=True)
        self.fc = torch.nn.Linear(hidden_dim, hidden_dim, bias=True)

    def forward(self, x):
        x, _status = self.rnn(x)
        x = self.fc(x)
        return x
net = Net(dic_size, hidden_size, 2)

# loss & optimizer setting
criterion = torch.nn.CrossEntropyLoss()
optimizer = optim.Adam(net.parameters(), learning_rate)
# start training
for i in range(100):
    optimizer.zero_grad()
    outputs = net(X)
    loss = criterion(outputs.view(-1, dic_size), Y.view(-1))
    loss.backward()
    optimizer.step()

    results = outputs.argmax(dim=2)
    predict_str = ""
    for j, result in enumerate(results):
        # print(i, j, ''.join([char_set[t] for t in result]), loss.item())
        if j == 0:
            predict_str += ''.join([char_set[t] for t in result])
        else:
            predict_str += char_set[result[-1]]

    print(predict_str)
Enter fullscreen mode Exit fullscreen mode

대면 8 April, 2023

gradient descent and linear regression

Q. train run을 여러번 돌릴 때, data 쪽 셀을 run하지 않고 돌리면 그 전 런타임에서 발생한 오버피팅이 그다음 런타임 시작부터 누적되어 발생하는 느낌? 왜 그런거지?

Q. train loss 왜 증가?
A. learning_rate 너무 컸음

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (0)

The Most Contextual AI Development Assistant

Pieces.app image

Our centralized storage agent works on-device, unifying various developer tools to proactively capture and enrich useful materials, streamline collaboration, and solve complex problems through a contextual understanding of your unique workflow.

👥 Ideal for solo developers, teams, and cross-company projects

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay