{"id":13337,"date":"2023-11-07T11:40:05","date_gmt":"2023-11-07T16:40:05","guid":{"rendered":"https:\/\/blogs.mathworks.com\/deep-learning\/?p=13337"},"modified":"2024-05-29T16:19:23","modified_gmt":"2024-05-29T20:19:23","slug":"pytorch-models-and-git-in-matlab-online","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/deep-learning\/2023\/11\/07\/pytorch-models-and-git-in-matlab-online\/","title":{"rendered":"PyTorch Models and Git in MATLAB Online"},"content":{"rendered":"<h6><\/h6>\r\n<em>The following post is from <\/em><a href=\"https:\/\/www.linkedin.com\/in\/yanndebray\/\"><em>Yann Debray<\/em><\/a><em>, Product Manager for MATLAB Online, and <\/em><a href=\"https:\/\/www.linkedin.com\/in\/sivylla-p-05865a82\/\"><em>Sivylla Paraskevopoulou<\/em><\/a><em>, Product Marketing Manager for AI.<\/em>\r\n<h6><\/h6>\r\nDo you use MATLAB Online to create AI workflows? Do you want to write trackable and shareable code?\r\n<h6><\/h6>\r\nThis blog post shows you how to (1) import models from PyTorch\u00ae using MATLAB Online, (2) use Git\u2122 source control in MATLAB Online, and (3) open MATLAB Online directly from GitHub\u00ae. For each of the steps of the workflow, we have included a short animation to help you replicate the step.\r\n<h6><\/h6>\r\n<img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-15401 \" src=\"https:\/\/blogs.mathworks.com\/deep-learning\/files\/2023\/11\/MLonline_pytorch_github-1.png\" alt=\"Import Pytorch models in MATLAB Online and use Git source control\" width=\"583\" height=\"219\" \/>\r\n<h6><\/h6>\r\n&nbsp;\r\n<h6><\/h6>\r\n<p style=\"font-size: 18px;\"><strong>Create and Clone GitHub Repository<\/strong><\/p>\r\nWe 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.\r\n<h6><\/h6>\r\n<img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-13364 size-full\" src=\"https:\/\/blogs.mathworks.com\/deep-learning\/files\/2023\/11\/create_clone_repo-1.gif\" alt=\"\" width=\"1510\" height=\"930\" \/>\r\n<h6><\/h6>\r\n<strong>Animated Figure:<\/strong> Create a GitHub repository and clone it with MATLAB Online.\r\n<h6><\/h6>\r\nWe 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.\r\n<h6><\/h6>\r\n<img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-13379 size-full\" src=\"https:\/\/blogs.mathworks.com\/deep-learning\/files\/2023\/11\/create_token.gif\" alt=\"\" width=\"1520\" height=\"930\" \/>\r\n<h6><\/h6>\r\n<strong>Animated Figure:<\/strong> Generate personal access token.\r\n<h6><\/h6>\r\n&nbsp;\r\n<h6><\/h6>\r\n<p style=\"font-size: 18px;\"><strong>Import Model from PyTorch in MATLAB Online<\/strong><\/p>\r\nStarting in MATLAB R2023b, you can import models from PyTorch in MATLAB Online. To show this functionality, we reused the code from the doc example <a href=\"https:\/\/www.mathworks.com\/help\/deeplearning\/ref\/importnetworkfrompytorch.html#mw_addb7732-c424-4797-9765-3992bcd9752e\">Import Network from PyTorch and Classify Image<\/a>. 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.\r\n<h6><\/h6>\r\n<ol>\r\n \t<li>We added the live script to Source Control.<\/li>\r\n \t<li>We committed the script.<\/li>\r\n \t<li>We pushed the script to the GitHub repository.<\/li>\r\n<\/ol>\r\n<h6><\/h6>\r\nObserve how fast and intuitive using Git source control in MATLAB Online is!\r\n<h6><\/h6>\r\n<img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-13382 size-full\" src=\"https:\/\/blogs.mathworks.com\/deep-learning\/files\/2023\/11\/create_push_mlx-1.gif\" alt=\"\" width=\"1510\" height=\"940\" \/>\r\n<h6><\/h6>\r\n<strong>Animated Figure:<\/strong> Push live script (importing PyTorch model) from MATLAB Online to your GitHub repository.\r\n<h6><\/h6>\r\nThen, we did a quick update to the repository\u2019s README from MATLAB Online and pushed the changes to the repository.\r\n<h6><\/h6>\r\n<img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-13385 size-full\" src=\"https:\/\/blogs.mathworks.com\/deep-learning\/files\/2023\/11\/update_readme.gif\" alt=\"\" width=\"1510\" height=\"940\" \/>\r\n<h6><\/h6>\r\n<strong>Animated Figure:<\/strong> Push updated README.\r\n<h6><\/h6>\r\n&nbsp;\r\n<h6><\/h6>\r\n<p style=\"font-size: 18px;\"><strong>Add MATLAB Online Button to Repository<\/strong><\/p>\r\nFinally, we added an \u201cOpen in MATLAB Online\u201d 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 <a href=\"https:\/\/www.mathworks.com\/products\/matlab-online\/git.html\">Open in MATLAB Online from GitHub<\/a>.\r\n<h6><\/h6>\r\n<img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-13388 size-full\" src=\"https:\/\/blogs.mathworks.com\/deep-learning\/files\/2023\/11\/matlab_badge-1.gif\" alt=\"\" width=\"1510\" height=\"940\" \/>\r\n<h6><\/h6>\r\n<strong>Animated Figure:<\/strong> Open code from GitHub repository with MATLAB Online.\r\n<h6><\/h6>","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/deep-learning\/files\/2023\/11\/MLonline_pytorch_github-1.png\" onError=\"this.style.display ='none';\" \/><\/div><p>\r\nThe following post is from Yann Debray, Product Manager for MATLAB Online, and Sivylla Paraskevopoulou, Product Marketing Manager for AI.\r\n\r\nDo you use MATLAB Online to create AI workflows? Do you... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/deep-learning\/2023\/11\/07\/pytorch-models-and-git-in-matlab-online\/\">read more >><\/a><\/p>","protected":false},"author":194,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[9,32,39,45],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/deep-learning\/wp-json\/wp\/v2\/posts\/13337"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/deep-learning\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/deep-learning\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/deep-learning\/wp-json\/wp\/v2\/users\/194"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/deep-learning\/wp-json\/wp\/v2\/comments?post=13337"}],"version-history":[{"count":12,"href":"https:\/\/blogs.mathworks.com\/deep-learning\/wp-json\/wp\/v2\/posts\/13337\/revisions"}],"predecessor-version":[{"id":15407,"href":"https:\/\/blogs.mathworks.com\/deep-learning\/wp-json\/wp\/v2\/posts\/13337\/revisions\/15407"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/deep-learning\/wp-json\/wp\/v2\/media?parent=13337"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/deep-learning\/wp-json\/wp\/v2\/categories?post=13337"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/deep-learning\/wp-json\/wp\/v2\/tags?post=13337"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}