Artificial Intelligence

Apply machine learning and deep learning

PyTorch Models and Git in MATLAB Online

The following post is from Yann Debray, Product Manager for MATLAB Online, and Sivylla Paraskevopoulou, Product Marketing Manager for AI.
Do you use MATLAB Online to create AI workflows? Do you want to write trackable and shareable code?
This blog post shows you how to (1) import models from PyTorch® using MATLAB Online, (2) use Git™ source control in MATLAB Online, and (3) open MATLAB Online directly from GitHub®. For each of the steps of the workflow, we have included a short animation to help you replicate the step.
Import Pytorch models in MATLAB Online and use Git source control

Create and Clone GitHub Repository

We first created a new GitHub repository with a README file. We cloned this repository in MATLAB Online, which copied all the files from the repository to a folder in our working directory.
Animated Figure: Create a GitHub repository and clone it with MATLAB Online.
We generated a personal access token to use in place of a password. We are going to need the token to authenticate with GitHub when pushing our new or updated files to the GitHub repository.
Animated Figure: Generate personal access token.

Import Model from PyTorch in MATLAB Online

Starting in MATLAB R2023b, you can import models from PyTorch in MATLAB Online. To show this functionality, we reused the code from the doc example Import Network from PyTorch and Classify Image. Once we confirmed that the code runs as expected (that is, the PyTorch model is successfully imported and the test image is correctly classified), in three quick steps we uploaded the code to our GitHub repository.
  1. We added the live script to Source Control.
  2. We committed the script.
  3. We pushed the script to the GitHub repository.
Observe how fast and intuitive using Git source control in MATLAB Online is!
Animated Figure: Push live script (importing PyTorch model) from MATLAB Online to your GitHub repository.
Then, we did a quick update to the repository’s README from MATLAB Online and pushed the changes to the repository.
Animated Figure: Push updated README.

Add MATLAB Online Button to Repository

Finally, we added an “Open in MATLAB Online” button to our GitHub repository. By clicking on the button, the GitHub repository opens directly in MATLAB Online (independently from the Git-tracked folder that we previously created). This makes it easy to share your code with your team or community. To learn more, see Open in MATLAB Online from GitHub.
Animated Figure: Open code from GitHub repository with MATLAB Online.
  • print


To leave a comment, please click here to sign in to your MathWorks Account or create a new one.