Access Python Library importing Keras
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi all,
I am triyng to call python scripts i allready wrote in matlab.
In specific i am trying call i python function which imports keras models i created and uses them to predict the input data like this:
from keras.models import load_model
from euclid_dist import euclid_dist
import numpy as np
class nn_handler:
def __init__(self, model_location='current_checkpoint_lstm_2'):
self.model = load_model(model_location,custom_objects={'euclid_dist':euclid_dist})
def prediction(self,X):
pred=self.model.predict(X)
return pred.reshape(pred.shape[0],9,3)
However i noticed that matlab is (amoungst others) not accepting python scripts importing keras.
For exmple if i write two scripts:
test.py:
import numpy
def foo():
return 'bar'
and test2.py: (i only change the import and are not even using it)
import keras
def foo():
return 'bar'
And call them in matlab, setting the version to my anaconda enviroment:
pyversion('C:\Users\lukas.scheunemann\AppData\Local\Continuum\miniconda3\envs\nnenv\pythonw.exe')
py.test.foo()
py.test2.foo()
The first one returns 'bar'. But the secound an error 'Undefined variable "py" or class "py.test2.foo".
Did i make a misstake installing keras so it can not be used?
Or is only a limited selection off python libraries supported unlike the official limitations , because it is not desired that people use python instead off aquivilent matlab packages. E.g. i am supposed to buy the deep learning toolbox.
1 comentario
ARUN
el 23 de Feb. de 2021
I am facing the same probelm, you got this resolved? I am trying to call the python script which contains the keras model imported through load_model as yours. I am getting the same undefined function error.
Respuestas (1)
Lukas Scheunemann
el 15 de Nov. de 2018
1 comentario
LEONARDO NUTI
el 3 de Abr. de 2022
Hey i'm facing same issue can you elaborate on how you saved arguments in .mat file? I've xgboost and nn models written in Python that I need to run thorugh MATLAB
Ver también
Categorías
Más información sobre Call Python from MATLAB en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!