Deepy | 基于 Numpy 深度学习库【巧优雅简单】

项目:Deepy

简介:它使用numpy进行计算。 API类似于PyTorch的API。

GitHub:

https://github.com/kaszperro/deepy

Demo:

在示例目录中有一个线性分类器,其准确率超过96%。

顺序模型的创建:

from deepy.module import Linear, Sequentialfrom deepy.autograd.activations import Softmax, ReLU
my_model = Sequential(
    Linear(28 * 28, 300),
    ReLU(),
    Linear(300, 300),
    ReLU(),
    Linear(300, 10),
    Softmax()
    )

损失:

from deepy.module import Linear
from deepy.autograd.losses import CrossEntropyLoss, MSELoss
from deepy.variable import Variable
import numpy as np

my_model = Linear(10, 10)

loss1 = CrossEntropyLoss()
loss2 = MSELoss()


good_output = Variable(np.zeros((10,10)))
model_input = Variable(np.ones((10,10)))
model_output = my_model(model_input)

error = loss1(good_output, model_output)# now you can propagate error backwards:error.backward()

优化:

from deepy.module import Linear
from deepy.autograd.losses import CrossEntropyLoss, MSELoss
from deepy.variable import Variable
from deepy.autograd.optimizers import SGD
import numpy as np


my_model = Linear(10, 10)

loss1 = CrossEntropyLoss()
loss2 = MSELoss()

optimizer1 = SGD(my_model.get_variables_list())

good_output = Variable(np.zeros((10,10)))
model_input = Variable(np.ones((10,10)))
model_output = my_model(model_input)

error = loss1(good_output, model_output)

# now you can propagate error backwards:
error.backward()

# and then optimizer can update variables:
optimizer1.zero_grad()
optimizer1.step()

原文发布于微信公众号 - 机器学习算法与Python学习(guodongwei1991)

原文发表时间:2019-03-28

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

扫码关注云+社区

领取腾讯云代金券