Error while calling a Python Module

4 ビュー (過去 30 日間)
Avinash Siravuru
Avinash Siravuru 2017 年 2 月 10 日
編集済み: ARUN 2021 年 2 月 24 日
The Setup: I have a deep net model trained in python (using keras and tensorflow packages). I saved the model file as a json file and weights in h5 format. I wrote a simple Python script that takes two arrays as input, runs the learned model and returns a prediction. My main file in matlab is providing the inputs to the python file, calling it to return a prediction, and then continues to do further computation on it.
The Problem: Everytime I call the python module from matlab, I get the following error: "Python Error: AttributeError: 'array.array' object has no attribute 'reshape'" My model in python requires a 4D array. Since I figured earlier, the hard way, that one can't pass a multi-dimensional array from matlab to python, I'm passing a 1D array to python and doing the necessary conversion there itself. While, the error says I can't reshape, when I run the same commands through the python interpreter, they work.
Any help to resolve this is much appreciated. Thanks!
  2 件のコメント
Robert Snoeberger
Robert Snoeberger 2017 年 2 月 10 日
編集済み: Robert Snoeberger 2017 年 2 月 10 日
To respond to your comment "when I run the same commands through the python interpreter, they work", the following is a way to hit the same error with the python interpreter.
>>> import array
>>> a = array.array('d', range(20))
>>> a.reshape((2,10))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'array.array' object has no attribute 'reshape'
>>>
Maybe a solution for the above will fix your issue.
ARUN
ARUN 2021 年 2 月 24 日
編集済み: ARUN 2021 年 2 月 24 日
Hello, I am doing exactly the same, but when I call the python script with the keras model loaded as .h5 from Matlab, I am getting a Matlab error. Can you suggest me how I can solve this issue?
Thanks in advance!

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeCall Python from MATLAB についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by