Matlab Import External Ai Model logo

Matlab Import External Ai Model

OrganizationPopular
matlab
matlab-import-external-ai-model

Import PyTorch, ONNX, or Keras 3 / TensorFlow 2.16+ deep learning models into MATLAB as dlnetwork objects. Use when importing .pt2 exported programs, traced .pt files, .onnx models, or Keras 3 models via matlabsaver. Covers importNetworkFromPyTorch, importNetworkFromONNX, importNetworkFromKeras, importNetworkFromTensorFlow, torch.export.export, PyTorchInputSizes, InputDataFormats, matlabsaver, tf_keras downgrade, numeric validation against PyTorch or ONNX Runtime, and placeholder/custom layer implementation. Applies when user mentions any of these functions, file formats, or encounters import errors, unsupported operator warnings, 0 learnables, or uninitialized networks.

Overview

Publishermatlab
Repositorymatlab-agentic-toolkit
Skill namematlab-import-external-ai-model
Stars
1.2K
Forks
138
Bundled files
9
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • 9 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

    Published by matlab on GitHub. Read the source before you install it.

Installation

Install the Matlab Import External Ai Model AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/matlab/matlab-agentic-toolkit/tree/main/skills-catalog/ai-and-statistics/matlab-import-external-ai-model
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/matlab/matlab-agentic-toolkit.git /tmp/matlab-agentic-toolkit
mkdir -p .claude/skills
cp -r /tmp/matlab-agentic-toolkit/skills-catalog/ai-and-statistics/matlab-import-external-ai-model .claude/skills/matlab-import-external-ai-model
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Matlab Import External Ai Model in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Matlab Import External Ai Model on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Matlab Import External Ai Model is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Import Deep Learning Models into MATLAB

Import trained PyTorch, ONNX, or Keras 3 models into MATLAB as dlnetwork objects and verify numerical correctness.

When to Use

  • User wants to import a deep learning model from PyTorch, ONNX, or Keras/TensorFlow
  • User has .pt2, .pt, .onnx, or .keras files to bring into MATLAB
  • User mentions importNetworkFromPyTorch, importNetworkFromONNX, importNetworkFromKeras, or importNetworkFromTensorFlow
  • User mentions torch.export.export, torch.jit.trace, PyTorchInputSizes, InputDataFormats, or matlabsaver
  • User encounters import errors, unsupported operator warnings, uninitialized networks, or 0 learnables after import
  • User wants to validate that an imported model matches the source framework's outputs

When NOT to Use

  • Exporting MATLAB networks to ONNX/PyTorch (use exportONNXNetwork / exportNetworkToPyTorch)
  • Training or fine-tuning after import — use /matlab-train-network
  • Deploying to embedded hardware — use /matlab-deploy-embedded-ai
  • Simulink integration after import (agent handles this well without guidance)

Router: Which Framework?

Q: What format is the source model?
 |
 +-- .pt2 (PyTorch exported program) ──────────> PYTORCH IMPORT below
 +-- .pt (PyTorch traced model) ───────────────> PYTORCH IMPORT below
 +-- .onnx ────────────────────────────────────> ONNX IMPORT below
 +-- .keras / TensorFlow 2.16+ / matlabsaver ──> KERAS IMPORT below
 +-- Unknown ("import my model") ──────────────> Ask: framework? file extension?

PyTorch Import

Full pipeline: export from PyTorch → import into MATLAB → validate numerics.

Determine Starting Point

User hasAction
PyTorch model (code or saved)Export as .pt2 first → see references/pytorch-export-guidance.md
.pt2 file (exported program)Import directly (below)
.pt file (traced model)Import with input sizes (below)

Always prefer .pt2 over .pt. If user has a traced model, recommend re-exporting with torch.export.export first. Only use traced path if re-export is not feasible.

Import .pt2 (Exported Program)

matlab
net = importNetworkFromPyTorch("model.pt2");

No input size argument needed — shape info is embedded in the .pt2 file.

Import .pt (Traced Model)

matlab
net = importNetworkFromPyTorch("model.pt", ...
    PyTorchInputSizes=[1 3 224 224]);

PyTorchInputSizes is mandatory for traced models. Specify sizes in PyTorch dimension ordering. For multiple inputs use a cell array: {[1 3 256 256], [1 10]}.

Name-Value Arguments

ArgumentWhen to use
PyTorchInputSizesRequired for traced models (.pt). Not needed for .pt2
NamespaceControl where auto-generated custom layer files are stored
PreferredNestingTypeChoose "networklayer" (default) or "customlayer"

PyTorch Critical Mistakes

MistakeCorrect Approach
Using InputShape NV argumentDoes not exist — use PyTorchInputSizes for .pt, nothing for .pt2
Using PackageName NV argumentDeprecated — use Namespace
Not calling model.to("cpu") before exportAlways model.to("cpu") before export
Not checking PyTorch version before exportAssert torch.__version__ starts with "2.8"
Passing PyTorchInputSizes for .pt2Unnecessary — .pt2 embeds shape info, omit it
Guessing input size for unknown modelsAlways ask the user for exact input dimensions
Assuming net.InputNames matches forward() orderImporter may reorder — always check net.InputNames

PyTorch Conventions

  • Always model.to("cpu") and model.eval() before export
  • Always verify PyTorch version is 2.8 before exporting as .pt2
  • Never guess input sizes — ask the user or inspect the model
  • Use Namespace not PackageName for custom layer storage
  • Prefer .pt2 over .pt — recommend torch.export.export over torch.jit.trace

PyTorch References

  • references/pytorch-export-guidance.md — Full Python-side export procedure
  • references/pytorch-import-guidance.md — Detailed MATLAB import for both formats
  • references/pytorch-numeric-validation.md — Dimension conversion and tolerance comparison
  • references/pytorch-placeholder-guidance.md — Implementing unsupported ops in custom layers
  • scripts/validateImportedNetwork.m — Helper function for numeric validation against .npy reference data

ONNX Import

Import ONNX models using importNetworkFromONNX, diagnose issues, verify numerics.

Workflow

1. IMPORT  → importNetworkFromONNX with appropriate NVPs
2. DIAGNOSE → Check initialization, custom layers, warnings
3. RESOLVE  → Fix issues (InputDataFormats, placeholder functions)
4. VERIFY   → Compare outputs against ONNX Runtime (if installed)

CRITICAL: Do NOT re-import after step 3. Re-importing regenerates +ops/ and overwrites all custom implementations.

Import

matlab
net = importNetworkFromONNX("model.onnx");

If you know the input format:

matlab
net = importNetworkFromONNX("model.onnx", InputDataFormats="BCSS");

Diagnose and Resolve

If net.Initialized is false, read the input shape and re-import with InputDataFormats:

matlab
net = importNetworkFromONNX("model.onnx");
if ~net.Initialized
    inputLayer = net.Layers(1);
    fprintf("NumDims: %d\n", inputLayer.NumDims);
end

InputDataFormats Reference

Characters: B (batch), C (channel), S (spatial), T (time), U (unspecified).

ONNX Input ShapeInputDataFormats
[N, C, H, W]"BCSS"
[N, C]"BC"
[N, T, C]"BTC"
[N, C, T]"BCT"

Verify Against ONNX Runtime

If onnxruntime is installed in the user's Python environment, compare outputs. If not installed, skip — do not ask the user to install it.

matlab
try
    ort = py.importlib.import_module("onnxruntime");
    ortAvailable = true;
catch
    ortAvailable = false;
end

See references/onnx-validation-workflow.md for the full comparison procedure.

ONNX Critical Mistakes

MistakeCorrect Approach
Use importONNXNetwork or importONNXLayersLegacy — always use importNetworkFromONNX
Re-import after implementing placeholdersImport once, then modify. Never re-import.
Guess InputDataFormats randomlyRead input shape from uninitialized network first
Skip numeric verification when ORT is availableCompare against ONNX Runtime if installed

ONNX Conventions

  • Always use importNetworkFromONNX — never legacy APIs
  • Verify numerically against ONNX Runtime after import (if installed)
  • Never re-import after modifying network or implementing placeholders
  • Use dlarray with explicit format strings: dlarray(data, "SSCB")
  • Report max absolute difference and assert tolerance < 1e-4 for float32

ONNX Reference

  • references/onnx-validation-workflow.md — Full ORT comparison including multi-output models

Keras Import

Import Keras 3 / TensorFlow 2.16+ models with full layer structure and learnables.

Decision Tree

Q1: What MATLAB release is available?
 +-- R2026a or newer ──> PATH 1 (matlabsaver + importNetworkFromKeras)
 +-- R2025b or older ──> Q2
      Q2: Does the model use Keras 3-specific features? (keras.ops, multi-backend)
       +-- No (standard layers) ──> PATH 2 (tf_keras downgrade)
       +-- Yes ────────────────────> PATH 3 (ONNX export fallback)

Path 1: matlabsaver + importNetworkFromKeras (R2026a+)

Python:

python
import matlabsaver
matlabsaver.save_for_matlab(model, "exportedModelFolder")

Apply the config.json patch for Keras 3.10+ compatibility (see references/keras-matlabsaver-workflow.md).

MATLAB:

matlab
net = importNetworkFromKeras("exportedModelFolder");
assert(numel(net.Learnables.Value) > 0, "Import failed: 0 learnables")

Path 2: tf_keras Downgrade (Pre-R2026a, Standard Layers Only)

Python:

python
import os
os.environ["TF_USE_LEGACY_KERAS"] = "1"  # MUST be before importing TensorFlow
import tf_keras as keras
model.save("savedModelFolder")

MATLAB:

matlab
net = importNetworkFromTensorFlow("savedModelFolder");

Path 3: ONNX Export (Fallback)

Requires tf2onnx in the Python environment: pip install tf2onnx

Python:

python
model.export("exportedModel.onnx", format="onnx")

MATLAB:

matlab
net = importNetworkFromONNX("exportedModel.onnx");

Keras Critical Mistakes

MistakeCorrect Approach
importNetworkFromKeras fails with "Brace indexing..."Keras 3.10+ changed config.json — apply the patch (see reference)
model.export("folder") then importNetworkFromTensorFlowNo keras_metadata.pb → 0 learnables. Use matlabsaver instead
TF_USE_LEGACY_KERAS=1 set after import tensorflowMust be set before any TF import
Using deprecated importKerasNetworkUse importNetworkFromKeras (R2026a+) or Path 2/3

Keras Conventions

  • Always verify imported network has non-zero learnables
  • Always check MATLAB release before choosing import path
  • Prefer Path 1 > Path 2 > Path 3 (ordered by fidelity)
  • Report number of layers and learnables after import

Keras References

  • references/keras-matlabsaver-workflow.md — Full matlabsaver procedure for R2026a+
  • references/keras-tf-keras-downgrade.md — tf_keras setup for pre-R2026a

Key Functions

FunctionFrameworkPurpose
importNetworkFromPyTorchPyTorchImport .pt2 or .pt as dlnetwork
importNetworkFromONNXONNXImport .onnx as dlnetwork
importNetworkFromKerasKerasImport Keras 3 folder as dlnetwork (R2026a+)
importNetworkFromTensorFlowTF/KerasImport TF SavedModel as dlnetwork
torch.export.exportPyTorchExport model as .pt2 (Python)
matlabsaver.save_for_matlabKerasExport Keras 3 for MATLAB (Python)
predictAllRun inference on imported dlnetwork
dlarrayAllLabeled multi-dimensional array for deep learning

Copyright 2026 The MathWorks, Inc.


Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the Matlab Import External Ai Model AI skill do?

Import PyTorch, ONNX, or Keras 3 / TensorFlow 2.16+ deep learning models into MATLAB as dlnetwork objects. Use when importing .pt2 exported programs, traced .pt files, .onnx models, or Keras 3 models via matlabsaver. Covers importNetworkFromPyTorch, importNetworkFromONNX, importNetworkFromKeras, importNetworkFromTensorFlow, torch.export.export, PyTorchInputSizes, InputDataFormats, matlabsaver, tf_keras downgrade, numeric validation against PyTorch or ONNX Runtime, and placeholder/custom layer implementation. Applies when user mentions any of these functions, file formats, or encounters impo...

Why use Matlab Import External Ai Model on TypingMind?

Because you install it once and use it with any model. Matlab Import External Ai Model is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Matlab Import External Ai Model in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/matlab/matlab-agentic-toolkit/tree/main/skills-catalog/ai-and-statistics/matlab-import-external-ai-model. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use Matlab Import External Ai Model?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Matlab Import External Ai Model?

As many as you like. As long as a model supports skills, you can use Matlab Import External Ai Model with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Matlab Import External Ai Model AI skill free?

It is published on GitHub by matlab. Check the repository for licensing terms. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇