Giter Club home page Giter Club logo

hcrot's People

Contributors

emeraldgoose avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

hcrot's Issues

Module Class Implementation

Dropout 레이어 구현이나 모델 구조 출력을 위한 Module 클래스 구현

class CNN(layers.Module):
    def __init__(self, num_classes=10):
        super().__init__()
        self.layer1 = layers.Sequential(layers.Conv2d(1,5,5), layers.ReLU(), layers.MaxPool2d(2,2))
        self.layer2 = layers.Sequential(layers.Conv2d(5,7,5), layers.ReLU(), layers.MaxPool2d(2,2))
        self.flatten = layers.Flatten()
        self.fc = layers.Linear(112, num_classes)

출력결과

CNN(
  (layer1): Sequential(
    (0): Conv2d(1, 5, kernel_size=(5, 5), stride=(1, 1), padding=(0, 0))
    (1): ReLU()
    (2): MaxPool2d(kernel_size=(2, 2), stride=(2, 2))
  )
  (layer2): Sequential(
    (0): Conv2d(5, 7, kernel_size=(5, 5), stride=(1, 1), padding=(0, 0))
    (1): ReLU()
    (2): MaxPool2d(kernel_size=(2, 2), stride=(2, 2))
  )
  (flatten): Flatten(start_dim=1, end_dim=-1)
  (fc): Linear(in_features=112, out_features=10, bias=True)
)

모델 레이어의 계산 순서는 상속하는 Module의 sequential에 저장되고 optimizer가 접근하여 backward 함수를 호출한다.

CrossEntropyLoss implementation

Issue

NLLLoss + LogSoftmax

  • PyTorch에서 CrossEntropyLoss는 NLLLoss와 Softmax의 조합으로 구현됩니다.
  • NLLLoss
    • NLLLoss의 y_pred는 모델의 출력값을 LogSoftmax를 통과시킨 값으로 사용합니다.
def NLLLoss(y_pred, label):
    batch = len(y_pred)
    return sum([-y_pred[i][label[i]] for i in range(batch)])/batch

def NLLLoss_deriv(y_pred):
    batch = len(y_pred)
    return [[y_pred[i][j]/batch for j in range(len(y_pred[0]))] for i in range(batch)]
  • LogSoftmax
def log_softmax(y_pred):
    import math
    r_ = softmax_(y_pred)
    return [[math.log(r_[i][j]) for j in range(len(r_[0]))] for i in range(len(r_))]

def log_softmax_deriv(y_pred, label):
    import math
    r_ = softmax_(y_pred)
    return [[r_[i][j]-1 if label[i]==j else r_[i][j] for j in range(len(r_[0]))] for i in range(len(r_))]

구현 계획

누구나 다 그럴싸한 계획을 갖고 있다

큰 범위의 구현 진행정도

  • MLP
  • #2
  • RNN

구체적인 구현 진행정도

MLP

  • Linear
  • CrossEntropyLoss, MSELoss
  • Optimizer(Gradient Descent)

CNN

  • Conv2d
  • Flatten
  • ReLU
  • MaxPool2d
  • AvgPool2d

RNN

  • #9
  • Embedding
  • LSTM

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.