MATLAB Answers

How can I use TensorFlow library from matlab environment?

487 views (last 30 days)
I want to use or access TensorFlow library from Matlab environment, especially for machine learning. How can I use TensorFlow library from matlab ?

  3 Comments

Royi Avital
Royi Avital on 11 Jul 2017
Really hope to see MATLAB support for Caffe / MxNet / CNTK / TensorFlow.
Who knows, maybe will have something soon.
David Willingham
David Willingham on 27 Aug 2020
Hi, MATLAB supports Framework Interoperability with ONNX and Tensorflow-Keras. More information on this can be found here.
Regards,
David Willingham
Deep Learning Product Manager, MathWorks
John Daniels
John Daniels on 22 Sep 2020
Hi David,
I currently have a CNN-LSTM model that I would like to call from MATLAB. It was developed in Keras 2.2.2. I have attempted a number of approaches that have all failed so far.
  1. I tried to use the model as a function that is called from Matlab however, MATLAB crashes whenever the tensorflow/keras library is included in the script.
  2. I tried to port the model over using the Tensorflow-Keras (importKerasLayers and importKerasNetwork) however the Conv1d layer is not available and custom layers can't seem to work given the 'channel last' format. In addition, it seems CNN-LSTM layers are not compatible.
Are there any solutions to this issue?
Best,
John.

Sign in to comment.

Accepted Answer

Louis Yu
Louis Yu on 5 May 2017
I've went about working on a middle-man solution for new users to Tensorflow that typically utilize Matlab. It's a simple GUI interface that auto-codes the user inputs in the Matlab GUI into a python script that can be run utilizing the Tensorflow Python Interface.
See the file exchange @ Tensorflow for Matlab
For more details on reasons for this implementation, a paper was written over the effort conducted "Benchmarking Open Source Machine Learning Frameworks and Development of Auto-coding Interface for Entry-Level Engineers" .
There is also a github repository I utilized for some test-cases that include Tensorflow snippets: Github Repository for Benchmarking

  2 Comments

Kenn
Kenn on 31 Jul 2017
@Louis Yu, congrats on your effort, Tensorflow for Matlab. It looks like it has high potential but there's something not quite right. I mentioned several bugs I found, which make it look like the code could never have worked. Perhaps an earlier, incomplete version got uploaded? Mind taking a look?
Louis Yu
Louis Yu on 5 Aug 2017
Updates have been made to the file exchange upload. I've added a few helpful pieces for new users.

Sign in to comment.

More Answers (4)

Tom Anderson
Tom Anderson on 15 Apr 2017
TensorFlow is a free Python library developed by Google Brain. As of April 2017, it has APIs in other languages (C++, Java and Go), but they are experimental.
MATLAB is a proprietary programming language developed by Mathworks (non-free). It has interfaces to other languages, including Python. Mathworks offers its own Neural Network Toolbox™. There are also plenty of other deep learning MATLAB toolboxes, many listed at http://deeplearning.net/software_links/.
However, running TensorFlow with MATLAB is not supported by TensorFlow or Mathworks. As we can see, the MathWorks File Exchange does not have http://au.mathworks.com/matlabcentral/fileexchange/?utf8=%E2%9C%93&term=tensorflow. Neither does GitHub https://github.com/search?utf8=%E2%9C%93&q=matlab+tensorflow&type=. Until there is a bridge between the two, I would suggest that we are best advised to learn TensorFlow in the supported language (Python). Alternatively, if you already have paid for the MATLAB licenses (Neural Network Toolbox $1,500 Individual) (or belong to an organisation that has), you may consider learning MATLAB and the Neural Network Toolbox. This field is moving quickly, so be prepared to keep paying for the new version of Neural Network Toolbox (updates are not included in the price).

  1 Comment

Christopher Stokely
Christopher Stokely on 1 Feb 2019
The MATLAB Neural network toolbos for an individual is about $50, not more than $1000. Look at the license options on the MathWorks website for individual license for noncommercial use.
The Rosetta Stone of deep learning is ONNX (Open Neural Network Exchange), which allows model's to be transferred (I think) between environments such as PyTorch, MXNet, Core ML, Caffe2, TensorFlow, Microsoft Cognitive Toolkit, and MATLAB - I think. Check it out for yourself by searching for the command
exportONNXNetwork
References:
1) Open Neural Network Exchange https://github.com/onnx
From Mathworks webpage description, see the attached figure to see a summary of supported deep learning frameworks.

Sign in to comment.




David Willingham
David Willingham on 27 Aug 2020
Hi,
MATLAB supports Framework Interoperability with ONNX and Tensorflow-Keras.
More information on this can be found here.
Regards,
David Willingham
Deep Learning Product Manager, MathWorks

  0 Comments

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!