burn/examples/pytorch-import
Guillaume Lagrange cdd1fa1672
Refactor tensor data (#1916)
* Move distribution to module

* Add new TensorData with serialization support

* Implement display and from for TensorData

* Add missing Cargo.lock

* Add missing bytemuck feature

* Add zeros, ones, full and random TensorData methods

* Refactor Data -> TensorData usage

* Fix tests

Since TensorData is not generic over the element type anymore no type inference can be done by the compiler. We must explicitly cast the expected results to the expected backend type.

* Remove commented line

* Fix import

* Add record-backward-compat

* Remove dim const generic from TensorData

* Support NestedValue de/serialization with TensorData

* Fix burn-jit tests

* Remove eprinln

* Refactor onnx import to use TensorData

* Fix tch from_data

* Fix nested value serialization for u8

* Fix missing import

* Fix reduce min onnx test

* Fix deprecated attribute

* Remove shape getter

* Remove strict assert in tests

* Add tensor data as_bytes

* Add tensor check for rank mismatch

* Fix typo (dimensions plural)

* Fix error message

* Update book examples with from_data and fix Display impl for TensorData

* Add deprecation note
2024-06-26 20:22:19 -04:00
..
model Bump next version of Burn to 0.14.0 (#1618) 2024-04-12 17:14:45 -04:00
pytorch Add support for loading PyTorch `.pt` (weights/states) files directly to model's record (#1085) 2024-01-25 10:20:09 -05:00
src Refactor tensor data (#1916) 2024-06-26 20:22:19 -04:00
Cargo.toml Fix `DataSerialize` conversion for elements of the same type (#1832) 2024-05-28 18:12:44 -04:00
README.md Add support for loading PyTorch `.pt` (weights/states) files directly to model's record (#1085) 2024-01-25 10:20:09 -05:00
build.rs Upgrade to candle 0.4.1 (#1382) 2024-02-29 11:29:11 -06:00

README.md

Import PyTorch Weights

This crate provides a simple example for importing PyTorch generated weights to Burn.

The .pt file is converted into a Burn consumable file (message pack format) using burn-import. The conversation is done in the build.rs file.

The model is separated into a sub-crate because build.rs needs for conversion and build.rs cannot import modules for the same crate.

Usage

cargo run -- 15

Output:

Finished dev [unoptimized + debuginfo] target(s) in 0.13s
    Running `burn/target/debug/onnx-inference 15`

Image index: 15
Success!
Predicted: 5
Actual: 5
See the image online, click the link below:
https://datasets-server.huggingface.co/assets/mnist/--/mnist/test/15/image/image.jpg