emeraldgoose / hcrot Goto Github PK
View Code? Open in Web Editor NEWDeep Learning Implementation from scratch using python
Deep Learning Implementation from scratch using python
np.reshape()를 구현하는 것이 맞을까?
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 함수를 호출한다.
Line 34 in b873b2b
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)]
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_))]
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.