Skip to content

Latest commit

 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JadeRain

一个轻量级的基于python的深度学习框架


Overview

JadeRain 是一个使用纯python实现的深度学习框架,无任何外部库的引用,是本人的练手之作,目前已有:

  • 动态计算图的构建与自动微分的实现
  • 张量类及其基本功能的实现,以及定义在张量上的部分的逐元素的操作、矩阵乘法以及广播的实现
  • 少数损失函数和优化器的实现
  • 提供统一的模型的api接口,可以统一化地进行线性模型的训练

环境

使用python 3.11版本进行功能搭建

快速开始

import jaderain as jr
from jaderain import JTensor, arrange_fn
from jaderain.nn.layer import Linear
from jaderain.nn.core import Module
from jaderain.losses.mse import MSELoss
from jaderain.optimizer.optimizer import SGD

#自定义模型
class Mynet(Module):
    def __init__(self, in_features):
        super().__init__()
        self.fc1 = Linear(in_features, 1)

    def forward(self, x):
        x = self.fc1(x)
        return x

#数据集生成
x, y = arrange_fn(0, 1, 0.005, lambda x:3 * x + 6)
#模型实例
net = Mynet(1)
#优化器和损失函数
sgd = SGD(net.parameters(), lr=1e-3)
loss_fn = MSELoss()
#训练
epoch = 200
for i in range(epoch):
    for datas in zip(x, y):
        f, l = datas
        features, labels = f.reshape((1, -1)), l.reshape((1, -1))
        output = net(features)
        loss = loss_fn(output, labels)
        sgd.zero_grad()
        loss.backward()
        sgd.step()
#验证
print(net(JTensor([10],shape=(1,1))))
#参数保存和读入
jr.save(net.state_dict(),'model.jr')
net.load_state_dict(jr.load('model.jr'))
print(net(JTensor([100],shape=(1,1))))

动机

本项目旨在通过从零实现动态计算图和自动求导引擎以及后续功能,加深对深度学习原理的理解,并提升编程能力。

致谢

感谢我的女友为我提供的帮助,JadeRain中的Rain就来自于她的名字

About

JadeRain – A lightweight, pure-Python dynamic deep learning framework.

Resources

Stars

6 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages