matlab-integrate-pytorch-vision

Creates MATLAB interfaces to Python computer vision models using MPyReq.

995|122|Updated Apr 3, 2026
One-click install
npx skills add https://github.com/matlab/matlab-agentic-toolkit --skill matlab-integrate-pytorch-vision
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: matlab-integrate-pytorch-vision
Source: https://github.com/matlab/matlab-agentic-toolkit/tree/main/skills-catalog/image-processing-and-computer-vision/matlab-integrate-pytorch-vision
Command: npx skills add https://github.com/matlab/matlab-agentic-toolkit --skill matlab-integrate-pytorch-vision

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Calling Python-based image processing and computer vision models from MATLAB normally requires manual environment setup, dependency resolution, and tedious tensor format conversions. This Skill automates the creation of MATLAB interfaces to PyTorch vision models from GitHub repositories or pip packages using the MPyReq framework.

Core Features & Use Cases

  • Automated Environment Setup: Generates MPyReq setup scripts that install the correct Python version, pip packages, git repositories, and model weights.
  • Python-to-MATLAB Translation: Converts Python inference code into idiomatic MATLAB, handling NCHW-to-HWC tensor reordering, bounding box format conversion, and context manager replacements.
  • Verified Execution: Tests generated scripts through the MATLAB MCP server with up to 5 fix-and-retry attempts, then delivers a structured handoff if issues remain.
  • Use Case: Given the GitHub URL for a segmentation model like SAM2 or BiRefNet, the Skill produces a tested demo<ModelName>.m script that downloads weights, runs inference on a MATLAB-loaded image, and visualizes the mask.

Quick Start

Ask your AI agent to create a MATLAB interface to a vision model by providing its GitHub repository URL, for example: create an MPyReq demo that runs the DepthPro depth estimation model from MATLAB.

Frequently Asked Questions about matlab-integrate-pytorch-vision

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I call a Python PyTorch vision model from MATLAB?

Use MPyReq to set up the Python environment with the required packages and weights, then call the model through MATLAB's py interface. This Skill generates a complete demo script that handles installation, model loading, inference, and result visualization.

How to convert PyTorch tensors to MATLAB arrays?

Call double(result.cpu().detach().numpy()) to get a MATLAB array, then permute dimensions from PyTorch's NCHW ordering to MATLAB's H x W x C x B ordering. Use squeeze to remove singleton batch dimensions before displaying.

Does MPyReq support models loaded with torch.hub?

Yes. Models using torch.hub.load() only need torch and torchvision installed as pip packages, since weights download automatically. No git clone or explicit weights download is required for this pattern.

Why can't MATLAB use Python with statements like torch.no_grad?

MATLAB cannot call Python dunder methods like __enter__ and __exit__ because double underscores are invalid MATLAB syntax. Use the functional equivalent py.torch.set_grad_enabled(false) before inference and set it back to true afterward.

When should I not use this Skill for Python-MATLAB interfacing?

Do not use it for non-vision models such as NLP, audio, or tabular data, for model deployment or serving, or for pure MATLAB image processing with no Python dependency. It is scoped specifically to image and computer vision models.

What happens if the generated MATLAB demo script fails during testing?

The Skill retries fixes up to 5 attempts through the MATLAB MCP server. If still failing, it returns the best working version with a structured handoff listing what works, remaining errors, and recommended next steps.