burn/burn-import
Dilshod Tadjibaev e2a17e4295
Add image classification web demo with WebGPU, CPU backends (#840)
2023-10-05 10:29:13 -04:00
..
onnx-tests Support no-std for models generated by burn-import (#822) 2023-09-21 11:43:07 -04:00
src Allow custom file location for loading record for ONNX model (#824) 2023-09-22 08:40:36 -04:00
Cargo.toml Add image classification web demo with WebGPU, CPU backends (#840) 2023-10-05 10:29:13 -04:00
DEVELOPMENT.md Update burn-import README (#727) 2023-08-30 08:20:53 -04:00
LICENSE-APACHE License fixes (#648) 2023-08-16 12:45:35 -04:00
LICENSE-MIT License fixes (#648) 2023-08-16 12:45:35 -04:00
README.md Update burn-import README (#727) 2023-08-30 08:20:53 -04:00
SUPPORTED-ONNX-OPS.md Update burn-import README (#727) 2023-08-30 08:20:53 -04:00
build.rs Add foundation for importing ONNX files (#297) 2023-04-15 10:44:50 -04:00

README.md

Burn Import: A Crate for ONNX Model Import into the Burn Framework

burn-import facilitates the seamless import of machine learning models, particularly those in the ONNX format, into the Burn deep learning framework. It automatically generates Rust source code, aligns the model structure with Burn's native format, and converts tensor data for Burn compatibility.

Note: This crate is in active development and currently supports a limited set of ONNX operators.

Working Examples

For practical examples, please refer to:

  1. ONNX Inference Example
  2. SqueezeNet Image Classification

Usage

Importing ONNX Models

Follow these steps to import an ONNX model into your Burn project:

  1. Update build.rs: Include the following Rust code in your build.rs file:

    use burn_import::onnx::ModelGen;
    
    fn main() {
        // Generate Rust code from the ONNX model file
        ModelGen::new()
            .input("src/model/mnist.onnx")
            .out_dir("model/")
            .run_from_script();
    }
    
  2. Modify mod.rs: Add this code to the mod.rs file located in src/model:

    pub mod mnist {
        include!(concat!(env!("OUT_DIR"), "/model/mnist.rs"));
    }
    
  3. Utilize Imported Model: Use the following sample code to incorporate the imported model into your application:

    mod model;
    
    use burn::tensor;
    use burn_ndarray::NdArrayBackend;
    use model::mnist::Model;
    
    fn main() {
        // Initialize a new model instance
        let model: Model<NdArrayBackend<f32>> = Model::new();
    
        // Create a sample input tensor (zeros for demonstration)
        let input = tensor::Tensor::<NdArrayBackend<f32>, 4>::zeros([1, 1, 28, 28]);
    
        // Execute the model
        let output = model.forward(input);
    
        // Display the output
        println!("{:?}", output);
    }
    

Contribution

Interested in contributing to burn-import? Check out our development guide for more information.