v0.1.0 · MIT 开源协议 · 零依赖 v0.1.0 · MIT License · Zero Dependencies

JavaScript
做深度学习
Deep Learning in
JavaScript

类似 PyTorch 的 JavaScript 张量与自动微分库。构建、训练、运行神经网络 —— 无需 Python。 A PyTorch-like tensor and autograd library for JavaScript. Build, train, and run neural networks — no Python required.

npm install estorch

为什么选择 EsTorch? Why EsTorch?

神经网络训练所需的一切,开箱即用。 Everything you need for neural network training, in the browser or Node.js.

自动微分引擎 Autograd Engine

基于计算图的自动微分。调用 backward(),梯度自动流过所有运算 —— 和 PyTorch 一样。 Automatic differentiation with a computation graph. Call backward() and gradients flow through your operations — just like PyTorch.

🧠

神经网络层 Neural Network Layers

内置 LinearConv2dAvgPool2dCrossEntropyLoss,以及提供 parameters()stateDict()Module 基类。 Built-in Linear, Conv2d, AvgPool2d, CrossEntropyLoss, and a Module base class with parameters() and stateDict().

📦

零依赖 Zero Dependencies

纯 JavaScript 实现,无任何外部依赖。只需 npm install estorch 即可开始训练。轻量且便携。 Pure JavaScript with no external packages. Just npm install estorch and you're ready to train. Lightweight and portable.

🔄

熟悉的 PyTorch API Familiar PyTorch API

如果你会 PyTorch,你就已经会 EsTorch。相同的类名、相同的方法签名、相同的训练循环模式。 If you know PyTorch, you already know EsTorch. Same class names, same method signatures, same training loop pattern.

📊

数据加载 Data Loading

内置 DataLoader,支持异步迭代器、批处理、随机打乱,以及开箱即用的 MNIST 数据集辅助工具。 Built-in DataLoader with async iterators, batch support, shuffling, and ready-to-use MNIST dataset helpers.

🛠️

优化器与调度器 Optimizers & Schedulers

Adam 优化器,支持配置学习率、beta 参数和 epsilon。StepLR 调度器用于训练过程中的学习率衰减。 Adam optimizer with configurable learning rate, betas, and epsilon. StepLR scheduler for learning rate decay during training.

简洁而富有表现力 Simple & Expressive

你熟悉的训练循环模式。 A familiar training loop you'll feel right at home with.

// 用约 10 行代码训练神经网络// Train a neural network in ~10 lines
const torch = require('estorch');

const model = new SimpleNet();
const criterion = new torch.nn.CrossEntropyLoss();
const optimizer = new torch.optim.Adam(model.parameters(), { lr: 0.001 });

for await (const [images, labels] of trainLoader) {
  optimizer.zeroGrad();
  const outputs = model.forward(images);
  const loss = criterion.forward(outputs, labels);
  loss.backward();
  optimizer.step();
}

API 一览 API at a Glance

熟悉的模块结构,灵感来自 PyTorch。 Familiar module structure, inspired by PyTorch.

torch

  • tensor()
  • randn()
  • zeros()
  • noGrad()
  • device()
  • save() / load()

torch.nn

  • Module
  • Parameter
  • Linear
  • Conv2d
  • AvgPool2d
  • CrossEntropyLoss

torch.optim

  • Adam
  • lrScheduler.StepLR

torch.data

  • DataLoader
  • randomSplit()
  • mnist.MNISTDataset
  • mnist.prepareMNIST()
  • mnist.downloadMNIST()
0 外部依赖 Dependencies
~15KB 包体积 Package Size
100% JavaScript JavaScript
MIT 开源协议 License

准备好了吗? Ready to Build?

今天就开始用 JavaScript 训练神经网络。 Start training neural networks in JavaScript today.

在 npm 上查看 View on npm 在 GitHub 上查看 View on GitHub