Imports PyTorch, ONNX, or Keras 3/TensorFlow 2.16+ deep learning models into MATLAB as dlnetwork objects.
Ships in ai-and-statistics. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
Import trained PyTorch, ONNX, or Keras 3 models into MATLAB as dlnetwork
objects and verify numerical correctness.
.pt2, .pt, .onnx, or .keras files to bring into MATLABimportNetworkFromPyTorch, importNetworkFromONNX, importNetworkFromKeras, or importNetworkFromTensorFlowtorch.export.export, torch.jit.trace, PyTorchInputSizes, InputDataFormats, or matlabsaverexportONNXNetwork / exportNetworkToPyTorch)/matlab-train-network/matlab-deploy-embedded-aiQ: 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?
Full pipeline: export from PyTorch → import into MATLAB → validate numerics.
| User has | Action |
|---|---|
| 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.
net = importNetworkFromPyTorch("model.pt2");
No input size argument needed — shape info is embedded in the .pt2 file.
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]}.
| Argument | When to use |
|---|---|
PyTorchInputSizes | Required for traced models (.pt). Not needed for .pt2 |
Namespace | Control where auto-generated custom layer files are stored |
PreferredNestingType | Choose "networklayer" (default) or "customlayer" |
| Mistake | Correct Approach |
|---|---|
Using InputShape NV argument | Does not exist — use PyTorchInputSizes for .pt, nothing for .pt2 |
Using PackageName NV argument | Deprecated — use Namespace |
Not calling model.to("cpu") before export | Always model.to("cpu") before export |
| Not checking PyTorch version before export | Assert torch.__version__ starts with "2.8" |
Passing PyTorchInputSizes for .pt2 | Unnecessary — .pt2 embeds shape info, omit it |
| Guessing input size for unknown models | Always ask the user for exact input dimensions |
Assuming net.InputNames matches forward() order | Importer may reorder — always check net.InputNames |
model.to("cpu") and model.eval() before exportNamespace not PackageName for custom layer storagetorch.export.export over torch.jit.tracereferences/pytorch-export-guidance.md — Full Python-side export procedurereferences/pytorch-import-guidance.md — Detailed MATLAB import for both formatsreferences/pytorch-numeric-validation.md — Dimension conversion and tolerance comparisonreferences/pytorch-placeholder-guidance.md — Implementing unsupported ops in custom layersscripts/validateImportedNetwork.m — Helper function for numeric validation against .npy reference dataImport ONNX models using importNetworkFromONNX, diagnose issues, verify numerics.
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.
net = importNetworkFromONNX("model.onnx");
If you know the input format:
net = importNetworkFromONNX("model.onnx", InputDataFormats="BCSS");
If net.Initialized is false, read the input shape and re-import with InputDataFormats:
net = importNetworkFromONNX("model.onnx");
if ~net.Initialized
inputLayer = net.Layers(1);
fprintf("NumDims: %d\n", inputLayer.NumDims);
end
Characters: B (batch), C (channel), S (spatial), T (time), U (unspecified).
| ONNX Input Shape | InputDataFormats |
|---|---|
| [N, C, H, W] | "BCSS" |
| [N, C] | "BC" |
| [N, T, C] | "BTC" |
| [N, C, T] | "BCT" |
If onnxruntime is installed in the user's Python environment, compare outputs. If not installed, skip — do not ask the user to install it.
try
ort = py.importlib.import_module("onnxruntime");
ortAvailable = true;
catch
ortAvailable = false;
end
See references/onnx-validation-workflow.md for the full comparison procedure.
| Mistake | Correct Approach |
|---|---|
Use importONNXNetwork or importONNXLayers | Legacy — always use importNetworkFromONNX |
| Re-import after implementing placeholders | Import once, then modify. Never re-import. |
| Guess InputDataFormats randomly | Read input shape from uninitialized network first |
| Skip numeric verification when ORT is available | Compare against ONNX Runtime if installed |
importNetworkFromONNX — never legacy APIsdlarray with explicit format strings: dlarray(data, "SSCB")references/onnx-validation-workflow.md — Full ORT comparison including multi-output modelsImport Keras 3 / TensorFlow 2.16+ models with full layer structure and learnables.
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)
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:
net = importNetworkFromKeras("exportedModelFolder");
assert(numel(net.Learnables.Value) > 0, "Import failed: 0 learnables")
Python:
import os
os.environ["TF_USE_LEGACY_KERAS"] = "1" # MUST be before importing TensorFlow
import tf_keras as keras
model.save("savedModelFolder")
MATLAB:
net = importNetworkFromTensorFlow("savedModelFolder");
Requires tf2onnx in the Python environment: pip install tf2onnx
Python:
model.export("exportedModel.onnx", format="onnx")
MATLAB:
net = importNetworkFromONNX("exportedModel.onnx");
| Mistake | Correct Approach |
|---|---|
importNetworkFromKeras fails with "Brace indexing..." | Keras 3.10+ changed config.json — apply the patch (see reference) |
model.export("folder") then importNetworkFromTensorFlow | No keras_metadata.pb → 0 learnables. Use matlabsaver instead |
TF_USE_LEGACY_KERAS=1 set after import tensorflow | Must be set before any TF import |
Using deprecated importKerasNetwork | Use importNetworkFromKeras (R2026a+) or Path 2/3 |
references/keras-matlabsaver-workflow.md — Full matlabsaver procedure for R2026a+references/keras-tf-keras-downgrade.md — tf_keras setup for pre-R2026a| Function | Framework | Purpose |
|---|---|---|
importNetworkFromPyTorch | PyTorch | Import .pt2 or .pt as dlnetwork |
importNetworkFromONNX | ONNX | Import .onnx as dlnetwork |
importNetworkFromKeras | Keras | Import Keras 3 folder as dlnetwork (R2026a+) |
importNetworkFromTensorFlow | TF/Keras | Import TF SavedModel as dlnetwork |
torch.export.export | PyTorch | Export model as .pt2 (Python) |
matlabsaver.save_for_matlab | Keras | Export Keras 3 for MATLAB (Python) |
predict | All | Run inference on imported dlnetwork |
dlarray | All | Labeled multi-dimensional array for deep learning |
Copyright 2026 The MathWorks, Inc.
manifest.yaml (opens in a new tab)references/keras-matlabsaver-workflow.md (opens in a new tab)references/keras-tf-keras-downgrade.md (opens in a new tab)references/onnx-validation-workflow.md (opens in a new tab)references/pytorch-export-guidance.md (opens in a new tab)references/pytorch-import-guidance.md (opens in a new tab)references/pytorch-numeric-validation.md (opens in a new tab)references/pytorch-placeholder-guidance.md (opens in a new tab)scripts/validateImportedNetwork.m (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
matlab, deep-learning, model-import, pytorch, onnx, keras, tensorflow, dlnetwork
/ai-and-statistics:matlab-import-external-ai-modelfrom ai-and-statistics
npx claudepluginhub matlab/matlab-agentic-toolkit --plugin ai-and-statistics10 skills in this plugin
/matlab-analyze-reliabilityUse this skill when fitting accelerated life models, computing mean time to failure (MTTF), B10 life and similar quantities, fitting life distributions like Weibull for reliability analysis, comparing distribution fits, computing confidence intervals on reliability quantities with bootstrapping, performing lifetime prediction, computing failure rates, plotting Kaplan-Meier curves, computing survival functions, or doing reliability analysis./matlab-classify-tabular-dataUse this skill to classify tabular data end-to-end in MATLAB — load a dataset, prepare and clean it, select promising classifiers, train them, and compare accuracies with cross-validation, holdout, or hyperparameter optimization plus statistical tests. TRIGGER when: user asks to classify tabular data, pick classifiers for a dataset, compare the accuracy of several classifiers by cross-validation or holdout, or find the best model with statistical uncertainty. DO NOT TRIGGER when: user has non-tabular inputs (images, sequences, time series), wants a regression model, wants the Classification or Regression Learner app (use matlab-use-machine-learning-apps), evaluates one model already chosen, is training a specific neural network architecture (use matlab-train-network), or wants cost-sensitive learning or an arbitrary class-prior vector (use fitc* with 'Prior' or 'Cost'; this skill only supports the built-in uniform-prior toggle).
/matlab-deploy-embedded-aiDeploy AI models to embedded hardware using MathWorks tools (MATLAB, Simulink, Embedded Coder). Covers two workflow patterns: (1) MathWorks-native or imported models rebuilt as dlnetwork for lean hardware, (2) direct C/C++ code generation from PyTorch and LiteRT models. Both patterns support all targets (Cortex-M/A/R, x86, GPU). Trigger when: user wants to deploy AI to embedded targets; generate C/CUDA from neural networks; compress AI models for MCU; integrate AI in Simulink for system-level simulation; import PyTorch/ONNX/TensorFlow models for embedded deployment; optimize AI for resource-constrained hardware; or use loadPyTorchExportedProgram, loadLiteRTModel, importNetworkFromPyTorch, importNetworkFromONNX, importNetworkFromTensorFlow, importNetworkFromKeras, dlquantizer, exportNetworkToSimulink, or Embedded Coder with AI models.
/matlab-engineer-tabular-featuresUse when engineering or selecting the best features for single-response classification or regression in MATLAB, whatever the data's modality — for non-tabular data it routes extraction to a domain skill, then selects, assesses, and delivers on the resulting table. Not for multi-response problems, model training, or raw data acquisition.
/matlab-fit-curveFit curves and surfaces interactively with the Curve Fitter app for a complete no-code fitting workflow. Invoke this skill when the Curve Fitter app, cftool, curveFitter, or "curve fitting tool/app" is mentioned in any way. Also use when exploring or comparing fit types (regression, interpolation, smoothing, splines, custom equations); excluding outliers interactively; iterating on a fitting workflow; help choosing a fit type; and exporting to a figure, generating MATLAB code, fits to the workspace, and to Simulink Lookup Tables./matlab-interpret-machine-learning-modelInterpret and explain a trained tabular machine-learning model (classification or regression) in MATLAB. Find which predictors, features, or columns matter most; explain why the model made a specific prediction, including diagnosing predictions it got wrong; show how a predictor affects the output; and compare how the model behaves across cohorts or subgroups. Uses model-agnostic techniques and model-native measures, and works on custom models (such as a dlnetwork) through a prediction function handle. Use for model interpretability, explainability, and feature-importance questions on tabular data, not for training, tuning, feature selection, deploying models, or models trained on image, text, signal, or other non-tabular data.Other plugins' skills for the same job