#neural-network #training #python #scratch #creation #simplifies #validation

ksnn

ksnn,或 Kosiorek 简单神经网络,是一个库,简化了神经网络的创建、训练和验证。该库深受 Harrison Kinsley 和 Daniel Kukieła 的《Python 从零开始神经网络》的启发。

3 个版本 (破坏性)

0.3.0 2022 年 7 月 18 日
0.2.0 2022 年 7 月 6 日
0.1.2 2022 年 7 月 5 日
0.1.1 2022 年 7 月 5 日

#600 in 机器学习

MIT/Apache

68KB
1K SLoC

ksnn

ksnn,或 Kosiorek 简单神经网络,是一个程序,简化了神经网络的创建、训练和验证。该程序深受 Harrison Kinsley 和 Daniel Kukieła 的《Python 从零开始神经网络》的启发。


lib.rs:

ksnn

ksnn,或 Kosiorek 简单神经网络,是一个库,简化了神经网络的创建、训练和验证。该库深受 Harrison Kinsley 和 Daniel Kukieła 的《Python 从零开始神经网络》的启发。

库 TODO

  • 提高库效率,可能通过多线程或从 CPU 将计算移动到 GPU
  • 添加更多网络类型,例如回归网络
  • 添加更多激活和熵函数

示例

如何创建 ClassificationNetwork

// Step 1: Get Training data and the anwsers for that data formatted in a 2d array.
let x_train = ndarray::arr2(&[
    [0.7, 0.29, 1.0, 0.55, 0.33, 0.27],
    [0.01, 0.08, 0.893, 0.14, 0.19, 0.98]
]);

let y_train = ndarray::arr2(&[
    [0, 0, 1],
    [0, 1, 0]
]);

// Step 2: Get testing data and the anwsers for that data formatted in a 2d array.
let x_test = ndarray::arr2(&[
    [0.64, 0.456, 0.68, 0.1, 0.123, 0.32],
    [0.78, 0.56, 0.58, 0.12, 0.37, 0.46]
]);

let y_test = ndarray::arr2(&[
    [1, 0, 0],
    [0, 1, 0]
]);

// Step 3: Create the network.
let mut neural_network = ksnn::ClassificationNetwork::new(
    vec!["ActivationReLU", "ActivationReLU", "ActivationReLU", "SoftmaxLossCC"],
    vec![32, 64, 48, 3],
    ksnn::enable_dropout_layers(true),
    ksnn::optimizers::optimizer_adam_def(),
    &x_train,
);

// Step 4: Adjust dropout layers, if enabled.
neural_network.dropout_layers[0].rate = 0.8;
neural_network.dropout_layers[1].rate = 0.75;
neural_network.dropout_layers[2].rate = 0.9;

// Step 5: Adjust weight regularizers as desired.
neural_network.dense_layers[0].weight_regularizer_l2 = 5e-4;
neural_network.dense_layers[0].bias_regularizer_l2 = 5e-4;

neural_network.dense_layers[1].weight_regularizer_l2 = 5e-3;
neural_network.dense_layers[1].bias_regularizer_l2 = 5e-3;

neural_network.dense_layers[2].weight_regularizer_l2 = 5e-5;
neural_network.dense_layers[2].bias_regularizer_l2 = 5e-5;

// Step 6: Fit, or train, the network on the training data.
neural_network.fit(100, 1, x_train, y_train);
// Step 6: Test your trained network on data it hasn't seen before to see how well it 
// deals with new information.
neural_network.validate(x_test, y_test);
// Step 7: Save your network to a file to be loaded and used later.
neural_network.save("my_network.json");

如何加载 ClassificationNetwork

let mut neural_network = ksnn::ClassificationNetwork::load("my_network.json");

依赖项

~6–15MB
~191K SLoC