- name
SKILL.md
Le fichier du skill reste dans le dépôt de l'éditeur.
Collez la commande copiée dans un terminal. Elle installe ce SKILL.md dans cet agent.
npx skills add matlab/matlab-agentic-toolkit --skill matlab-import-external-ai-model -a cursor -yCollez la commande copiée dans un terminal. Elle installe ce SKILL.md dans cet agent.
npx skills add matlab/matlab-agentic-toolkit --skill matlab-import-external-ai-model -a claude-code -yCollez la commande copiée dans un terminal. Elle installe ce SKILL.md dans cet agent.
npx skills add matlab/matlab-agentic-toolkit --skill matlab-import-external-ai-model -a codex -yCollez la commande copiée dans un terminal. Elle installe ce SKILL.md dans cet agent.
npx skills add matlab/matlab-agentic-toolkit --skill matlab-import-external-ai-model -a grok -yEnvoyez le message copié dans un chat Grok Bot. Le Bot récupère ce SKILL.md sur GitHub et l'ajoute aux skills que partagent tous vos Bots.
Install this skill: https://github.com/matlab/matlab-agentic-toolkit/tree/HEAD/skills-catalog/ai-and-statistics/matlab-import-external-ai-modelDe l'éditeur
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.
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]}.
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).
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.
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");
references/keras-matlabsaver-workflow.md — Full matlabsaver procedure for R2026a+references/keras-tf-keras-downgrade.md — tf_keras setup for pre-R2026aCopyright 2026 The MathWorks, Inc.
>
---name: matlab-import-external-ai-modeldescription: >---# skills-catalog/ai-and-statistics/matlab-import-external-ai-model/SKILL.mdFAQ
Téléchargez skills-catalog/ai-and-statistics/matlab-import-external-ai-model/SKILL.md auprès de l'éditeur, ou copiez le chemin et ouvrez le dépôt. PlugMCP répertorie le skill et n'héberge pas le fichier.
L'éditeur le maintient sur https://github.com/matlab/matlab-agentic-toolkit.
Claude, Cursor, Codex et Grok Build peuvent lire un SKILL.md que vous ajoutez depuis le dépôt de l'éditeur. Grok Bot l'installe lorsque vous envoyez dans un chat le lien du dossier GitHub du skill.