Run pickle file in matlab
조회 수: 254 (최근 30일)
이전 댓글 표시
I have machines learning model developed by python and saved as pickle file how can i run it in matlab
댓글 수: 1
Jan
2022년 6월 12일
The questions contains too few information to be answered. What exactly is your problem?
답변 (1개)
Al Danial
2022년 6월 13일
This shows how to load a pickle file into MATLAB:
pickle = py.importlib.import_module('pickle');
fh = py.open('data.pkl', 'rb')
P = pickle.load(fh); % pickle file loaded to Python variable
fh.close();
mP = py2mat(P); % pickle data converted to MATLAB native variable
The last line uses the py2mat.m utility. I tested this with the file data.pkl , created with this Python program,
#!/usr/bin/env python3
import pickle
import numpy as np
cm = np.array([[2., 3],[0, 1]]) - np.eye(2)*1j
a_list = ['this', 'is', 'a', 'complex', 'matrix', cm]
a_dict = { 1 : 1, 2 : 'two', 'three' : 3}
an_int = 42
some_bytes = b'1ee50ffe2fb5104144142f001a8ca94ae56b90cf'
X = np.arange(12,dtype=np.float16).reshape(3,4)
P = {
'a_list' : a_list,
'a_dict' : a_dict,
'an_int' : an_int,
'some_bytes' : some_bytes,
'X' : X,
}
with open('data.pkl', 'wb') as fh:
pickle.dump(P, fh, pickle.HIGHEST_PROTOCOL)
However this merely loads the contents of the pickle file. Running the machine learning model in MATLAB is something else entirely.
댓글 수: 1
Aymane ahajjam
2024년 4월 5일
@Al Danial, can you help with running the pickle-loaded machine learning model in matlab then?
Thank you eitherway!
참고 항목
카테고리
Help Center 및 File Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!