.. _tabular-exporting-models: ================ Exporting Models ================ This page covers how to export your NeurEco Tabular models for deployment in various formats and environments. .. contents:: On this page :local: :depth: 2 Export Formats Overview ======================= NeurEco Tabular models can be exported to multiple formats: **Native Format** .. list-table:: :header-rows: 1 :widths: 15 15 70 * - Format - Extension - Description * - NeurEco - ``.ednn`` - Native format for continued work in NeurEco or Python API **Deployment Formats** (require *embed* license) .. list-table:: :header-rows: 1 :widths: 15 15 70 * - Format - Extension - Best For * - FMU - ``.fmu`` - Simulation environments (Simulink, Dymola, OpenModelica, etc.) * - ONNX - ``.onnx`` - Cross-platform deployment, ML framework integration * - C Header - ``.h`` - Embedded systems, microcontrollers, high-performance applications * - VBA - ``.bas`` - Microsoft Excel integration Export Workflow =============== .. tabs:: .. tab:: GUI **1. Access the Export panel** Switch to the **Export** tab in NeurEco GUI. **2. Select checkpoint (optional)** Use the checkpoint slider to choose which model to export (default: final model). **3. Choose export format** Click the button for your desired format: - **Save** — NeurEco native format (.ednn) - **FMU** — Functional Mock-up Unit - **ONNX** — Open Neural Network Exchange - **C** — C header file - **VBA** — Visual Basic for Applications **4. Select precision (if applicable)** For some formats, choose the numerical precision: - **float64** — 64-bit (highest accuracy) - **float32** — 32-bit (good balance) - **float16** — 16-bit (smallest size) **5. Specify output path** Choose the destination filename and location. .. tab:: Python API **Save in native format:** .. code-block:: python model.save("./model/regression.ednn") **Export to FMU:** .. code-block:: python model.export_fmu("./model/regression.fmu") **Export to ONNX:** .. code-block:: python model.export_onnx("./model/regression.onnx", precision="float32") **Export to C header:** .. code-block:: python model.export_c("./model/regression.h", precision="float64") **Export to VBA:** .. code-block:: python model.export_vba("./model/regression.bas", precision="float32") .. tab:: CLI **Export commands:** .. code-block:: shell # Export to C neureco Regression exportC ./model/regression.ednn ./model/regression.h float64 # Export to ONNX neureco Regression exportONNX ./model/regression.ednn ./model/regression.onnx float32 # Export to VBA neureco Regression exportVBA ./model/regression.ednn ./model/regression.bas float32 # Export to FMU (last argument: platform flag, 3 = Windows and Linux) neureco Regression exportFMU ./model/regression.ednn ./model/regression.fmu 3 Format Details ============== Native NeurEco Format (.ednn) ----------------------------- The native format preserves all model information and is used for: - Continued work in NeurEco - Python API integration - Re-exporting to other formats later .. code-block:: python # Save model.save("model.ednn") # Load later model = Tabular.Regressor() model.load("model.ednn") FMU (Functional Mock-up Unit) ----------------------------- FMU is a standard for exchanging simulation models. Use it with: - MATLAB/Simulink - Dymola - OpenModelica - AMESim - Other FMI-compatible tools The exported FMU contains the neural network as a self-contained simulation component. **Usage in Simulink:** 1. Export model as FMU 2. In Simulink, add an FMU Import block 3. Browse and select the .fmu file 4. Connect inputs and outputs ONNX (Open Neural Network Exchange) ----------------------------------- ONNX is an open format for ML models, enabling interoperability with: - TensorFlow - PyTorch - ONNX Runtime - Many other frameworks **Using the ONNX model** (with ONNX Runtime; install it with ``pip install onnxruntime`` if needed): .. code-block:: python import onnxruntime as ort import numpy as np # Load the ONNX model session = ort.InferenceSession("model.onnx") # Get input name input_name = session.get_inputs()[0].name # Run inference x_test = np.array([[1.0, 2.0, 3.0]], dtype=np.float32) result = session.run(None, {input_name: x_test}) print(result[0]) C Header File ------------- The C export produces a standalone header file containing: - Network weights and biases - Inference function - No external dependencies **Using the C header:** .. code-block:: c #include "model.h" int main() { double inputs[5] = {1.0, 2.0, 3.0, 4.0, 5.0}; double outputs[1]; // Run inference neureco_evaluate(inputs, outputs); printf("Prediction: %f\n", outputs[0]); return 0; } This is ideal for: - Microcontrollers (Arduino, STM32, etc.) - Embedded systems - Real-time applications - Environments without Python VBA (Visual Basic for Applications) ----------------------------------- VBA export enables using NeurEco models directly in Microsoft Excel. **Using in Excel:** 1. Export model to .bas file 2. Open Excel, press Alt+F11 to open VBA editor 3. Import the .bas module 4. Use the function in your spreadsheet: .. code-block:: text =NeurEcoPredict(A1, B1, C1, D1, E1) Precision Options ================= When exporting, you can choose numerical precision: .. list-table:: :header-rows: 1 :widths: 15 25 60 * - Precision - Bits - Use Case * - ``float64`` - 64-bit - Maximum accuracy, scientific computing * - ``float32`` - 32-bit - Good balance of accuracy and size, most applications * - ``float16`` - 16-bit - Memory-constrained devices, when slight accuracy loss is acceptable **Recommendation:** Start with ``float32`` for most applications. Use ``float64`` only if you observe precision issues, and ``float16`` only when memory is critical. .. note:: The legacy names ``float`` and ``double`` remain accepted as aliases for ``float32`` and ``float64`` in the Python API, the CLI and configuration files, so existing scripts keep working. Exporting Compression Models ============================ Compression models produce three separate files: .. code-block:: python # During build, specify all three output paths config = Tabular.CompressorBuildConfig( input_data=x_train, write_model_to="./model/complete.ednn", # Full pipeline write_compression_model_to="./model/encoder.ednn", # Encoder only write_decompression_model_to="./model/decoder.ednn", # Decoder only ) Each can be exported independently: .. code-block:: python # Export encoder for embedded device encoder = Tabular.Compressor() encoder.load("./model/encoder.ednn") encoder.export_c("./embedded/encoder.h", precision="float32") # Export decoder for server decoder = Tabular.Compressor() decoder.load("./model/decoder.ednn") decoder.export_onnx("./server/decoder.onnx", precision="float32") Exporting from Checkpoints ========================== You can export any model from the checkpoint history: .. tabs:: .. tab:: GUI Use the checkpoint slider to select the model, then export normally. .. tab:: Python API .. code-block:: python # Load a specific checkpoint model (index 5 = "Checkpoint 6" in the log and the GUI) model = Tabular.Regressor() model.load_model_from_checkpoint("./model/regression.checkpoint", model_index=5) # Export it model.export_onnx("./model/checkpoint_6.onnx", precision="float32") Best Practices ============== 1. **Choose the right format:** Match the export format to your deployment environment 2. **Test after export:** Verify that the exported model produces the same results as the original 3. **Consider precision tradeoffs:** Lower precision saves memory but may affect accuracy 4. **Keep the native format:** Always save in .ednn format as a backup 5. **Document model inputs/outputs:** Keep track of input feature order and scaling Verifying Exported Models ========================= After exporting, verify the model works correctly: .. code-block:: python import onnxruntime as ort import numpy as np # Original NeurEco evaluation original_output = model.evaluate(x_test) # ONNX evaluation session = ort.InferenceSession("model.onnx") input_name = session.get_inputs()[0].name onnx_output = session.run(None, {input_name: x_test.astype(np.float32)})[0] # Compare max_diff = np.max(np.abs(original_output - onnx_output)) print(f"Maximum difference: {max_diff}") if max_diff < 1e-5: print("Export verification: PASSED") else: print("Export verification: Check precision settings") Next Steps ========== - :ref:`Convert to Keras or PyTorch ` for deep learning frameworks - :ref:`Use advanced features ` for model analysis