Skip to main content

使用 NumPy 的神经网络。

项目描述

Python 皮皮 地位 文档 网站

1. 目录

2. 概述

2.1。关于

NETS是一个轻量级的深度学习Python包,仅(大部分)使用numpy制作。该项目最初是作为 奥斯陆大学的一项作业引入的,类似于斯坦福大学的第二项作业。

但是,该项目被进一步推动,以使其具有更简单的 API 的OOP 。此外,使用自定义autograd系统更改了反向传播和更新规则。 NETS的灵感来自PyTorchTensorFlow 包。

但为什么 ?

NETS包没有声称可以影响已经构建好的深度学习包,如PyTorchTensorFlow。相反,这个包是为了理解所有这些库是如何工作的,并通过从头开始制作一个来处理前向/后向传播。当我经历这种深刻的理解时,我发现尽可能多地分享我的工作很有趣,我希望这将有助于学生或想要更多地了解这个主题的人。

2.2. 要求

NETS中的所有包都是从头开始制作的,主要使用numpy。但是,如果安装一些额外的包可以提供更好的体验(例如保存检查点和模型)。

  • 麻木的
  • json (可选)
  • 时间(可选)
  • 熊猫(可选)
  • scipy(可选)
  • sklearn(可选)

2.3. 安装

PyPi安装这个包

$ pip install nets

或来自此存储库

$ git clone https://github.com/arthurdjn/nets
$ cd nets
$ pip install .

3.状态

发展 地位 特征
Autograd系统 完成的
  • [x] 张量
  • [x] 参数
优化 完成的
  • [x] 新元
  • [x] 亚当
  • [x] RMSprop
失利 进行中
  • [x] MSE
  • [x] 交叉熵
  • [ ] 公元前
求解器 完成的
  • [x] 火车
  • [x] 评估
  • [x] 检查点
数据 完成的
  • [x] 数据集
  • [x] 批次
  • [x] 迭代器
密集神经网络 完成的
  • [x] 线性
  • [x] 顺序
卷积神经网络 完成的
  • [x] Conv2d
  • [x] MaxPool2d
  • [x] 辍学
递归神经网络 进行中
  • [x] 循环神经网络
  • []LSTM
  • [ ] 格鲁乌

4. 文档

文档和教程正在制作中,很快就会发布。您将找到一些关于如何开始或构建类似包的教程和应用程序。

5. 开始

NETS架构遵循PyTorch的架构。它提供了一个基本的神经网络结构,因此您可以使用 numpy 创建自己的。您需要将数组包装在一个Tensor类中以跟踪渐变,就像在PyTorch中一样。

网

5.1。计算图

NETS使用前向和后向传递进行梯度下降优化(注意:现在还有其他优化器!)。

您还可以使用 autograd 系统(推荐)。它的行为与 Pytorch 类似,只是它完全由 NumPy 完成。

import nets


t1 = nets.Tensor([1, 2, 3], require_grad=True)
t2 = nets.Tensor([4, 5, 6])

t3 = t1 + t2  
# t3 now requires gradient
t3 = t3.sum()
# Compute the gradients for t1
t3.backward()

5.2. 建立模型

模型是一个Module子类,其中计算偏差、权重和参数转换。所有模块都有一个forward方法,必须被覆盖。该方法将从输入张量计算前向传播,并计算变换。如果使用该autograd系统,则无需添加反向传播。但是,如果您更喜欢手动计算梯度,则需要覆盖该backward方法。

Model应该从Module该类继承并覆盖该forward方法。

import nets
import nets.nn as nn

class Model(nn.Module):
    """
    Create your own model.
    The attributes should be your submodels used during the forward pass.
    You don't have to necessary affect the activation function as an attribute,
    unless you want to set a manual backward pass.
    """
    def __init__(self, input_dim, hidden_dim, output_dim):
        # Initialization
        super().__init__() # Don't forget to add this line
        self.layer1 = nn.Linear(input_dim, hidden_dim)
        self.layer2 = nn.Linear(hidden_dim, hidden_dim)
        self.layer3 = nn.Linear(hidden_dim, output_dim)

    def forward(self, inputs):
        # Forward pass
        out1 = nets.tanh(self.layer1(inputs))
        out2 = nets.tanh(self.layer2(out1))
        return self.layer3(out2)

model = Model(10, 100, 2)

# Let's check the architecture
model

出去:

Model(
   (layer1): Linear(input_dim=10, output_dim=100, bias=True)
   (layer2): Linear(input_dim=100, output_dim=100, bias=True)
   (layer3): Linear(input_dim=100, output_dim=2, bias=True)
)

同样,这与PyTorch提供的非常相似。

6. 笔记本

7. 参考文献

这是帮助开发NETS的教程和讲座/作业的列表

项目详情


下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

源分布

nets-0.0.3.1.tar.gz (5.9 MB 查看哈希

已上传 source

内置分布

nets-0.0.3.1-py3-none-any.whl (71.2 kB 查看哈希)

已上传 py3