Package Exports
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (wrapture) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
π Wrapture
One-click exporter from PyTorch models to Web-ready ONNX with JS/TS wrappers.
About
Wrapture lets you go from a Python-trained model to deployable JavaScript with a single command. It generates TypeScript bindings and a Web/Node-compatible wrapper, using WebGPU/WASM-ready ONNX runtimes.
[!NOTE] This is an experiment trying to fulfil a need between python and js. YMMV
Table of Contents
π Features
- β Convert PyTorch models to ONNX
- β Optional ONNX simplification and quantization
- β
Generate
loadModel()
+predict()
JavaScript wrappers - β
Auto-generate
.d.ts
TypeScript bindings
Prerequisites
Python 3.10+ required
Install Python if you donβt have it: π https://www.python.org/downloads/
Install required Python packages
python3 -m pip install torch onnx onnxsim onnxruntime
Check your installation:
python3 -c "import torch; print(torch.__version__)"
python3 -c "import onnx; print(onnx.__version__)"
You should see output like:
2.x.x
etc..
Installation
npm i -g wrapture
Generating a Model
A helper script is provided to create a basic test model.
python3 python/scripts/basic_model.py
This generates:
test/fixtures/basic_model.pt
Usage
wrapture --input test/fixtures/basic_model.pt --output ./wrapped
Youβll see a spinner as the model is converted, and then a JS/TS wrapper is written to the ./wrapped/ directory.
Output Structure
Example contents of a --output ./
folder:
/
βββ wrapped.ts # The loadModel() + predict() logic
βββ wrapped.d.ts # Fully typed API
βββ model.onnx # Exported ONNX model
Example: Using the Generated Model
import { loadModel } from './wrapped.js';
const model = await loadModel();
const input = { data: new Float32Array(1 _3_ 224 \* 224), dims: [1, 3, 224, 224]
};
const result = await model.predict(input); console.log(result); // { // logits:
Float32Array, // probabilities: number[], // predictedClass: number // }
API
Full API documentation is available here.
Contributing
Want to contribute? Please read the CONTRIBUTING.md and CODE_OF_CONDUCT.md
License
This project is licensed under the MIT License - see the LICENSE file for details.
Changelog
See the CHANGELOG.md for details on the latest updates.
Sponsor me
I'm an Open Source evangelist, creating stuff that does not exist yet to help get rid of secondary activities and to enhance systems already in place, be it documentation or web sites.
The sponsorship is an unique opportunity to alleviate more hours for me to maintain my projects, create new ones and contribute to the large community we're all part of :)
Support me on GitHub Sponsors.
p.s. Ukraine is still under brutal Russian invasion. A lot of Ukrainian people are hurt, without shelter and need help. You can help in various ways, for instance, directly helping refugees, spreading awareness, putting pressure on your local government or companies. You can also support Ukraine by donating e.g. to Red Cross, Ukraine humanitarian organisation or donate Ambulances for Ukraine.