2个版本
0.2.1 | 2019年4月23日 |
---|---|
0.2.0 | 2019年4月7日 |
668 在 机器学习 分类中
每月27次下载
28KB
581 行
pyrus-nn
使用Rust编写的轻量级神经网络框架,具有薄的Python绑定。
-
功能
- 将网络序列化为YAML & JSON!
- Rust -> serde 兼容
- Python ->
network.to_dict()
&Sequential.from_dict()
- Python安装无需依赖
- 无需安装外部系统库
- 将网络序列化为YAML & JSON!
-
缺点
- 仅支持通用梯度下降。
- 目前仅支持全连接(密集)层
- 激活函数仅限于线性、tanh、sigmoid和softmax
- 损失函数仅限于MSE、MAE、交叉熵和准确率
安装
Python
pip install pyrus-nn # Has ZERO dependencies!
Rust
[dependencies]
pyrus-nn = "0.2.0"
从Python
from pyrus_nn.models import Sequential
from pyrus_nn.layers import Dense
model = Sequential(lr=0.001, n_epochs=10)
model.add(Dense(n_input=12, n_output=24, activation='sigmoid'))
model.add(Dense(n_input=24, n_output=1, activation='sigmoid'))
# Create some X and y, each of which must be 2d
X = [list(range(12)) for _ in range(10)]
y = [[i] for i in range(10)]
model.fit(X, y)
out = model.predict(X)
从Rust
use ndarray::Array2;
use pyrus_nn::{network::Sequential, layers::Dense};
// Network with 4 inputs and 1 output.
fn main() {
let mut network = Sequential::new(0.001, 100, 32, CostFunc::CrossEntropy);
assert!(
network.add(Dense::new(4, 5)).is_ok()
);
assert!(
network.add(Dense::new(5, 6)).is_ok()
);
assert!(
network.add(Dense::new(6, 4)).is_ok()
);
assert!(
network.add(Dense::new(4, 1)).is_ok()
);
let X: Array2<f32> = ...
let y: Array2<f32> = ...
network.fit(X.view(), y.view());
let yhat: Array2<f32> = network.predict(another_x.view());
}
依赖项
~10MB
~207K SLoC