Why do I get the message “Python DeprecationWrapper with no properties” when I try to load a Python module in MATLAB?

8 ビュー (過去 30 日間)
As an example, when I try to import TensorFlow (version 1.14.0) in MATLAB R2020b with Python 3.7.9 I get the following message
>> py.importlib.import_module('tensorflow')
ans =
Python DeprecationWrapper with no properties.
<module 'tensorflow' from 'C:\\Users\\<username>\\AppData\\Local\\Programs\\Python\\Python37\\lib\\site-packages\\tensorflow\\__init__.py'>
Why am I getting this message and how can I load my module?

採用された回答

MathWorks Support Team
MathWorks Support Team 2021 年 4 月 20 日
This issue stems from a Python warning(s)  that some features will be deprecated in the future. If you attempt to import a deprecated version of TensorFlow directly into Python you will see these types of messages:
Python 3.7.9 (tags/v3.7.9:13c94747c7, Aug 17 2020, 18:58:18) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
C:\Users\<username>\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\framework\dtypes.py:516: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_qint8 = np.dtype([("qint8", np.int8, 1)])
...
Attempting to import a module with deprecation warnings into MATLAB will return a Python DeprecationWrapper object with no properties. In these cases, the best solution is to update to a newer version of the module.
If updating to a newer version is not feasible, you can try the following workaround using Python’s getattr function. The example, below, uses the previous TensorFlow example with a workaround to access the TensorFlow constant function.
>> m = py.importlib.import_module('tensorflow');
>> f = py.getattr(m,'constant')
f =
Python function with no properties.
<function constant_v1 at 0x0000026AA97FA798>
>> c = f(1)
c =
Python Tensor with properties:
device: [1×0 py.str]
dtype: [1×1 py.tensorflow.python.framework.dtypes.DType]
graph: [1×1 py.tensorflow.python.framework.ops.Graph]
name: [1×7 py.str]
op: [1×1 py.tensorflow.python.framework.ops.Operation]
shape: [1×1 py.tensorflow.python.framework.tensor_shape.TensorShape]
value_index: [1×1 py.int]
Tensor("Const:0", shape=(), dtype=float32)

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by