Python “不推荐使用 type 的同义词;在 numpy 的未来版本中,它将被理解为 (type, (1,)) / '(1,)type'。” TensorFlow 中的问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/57381430/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 20:39:31  来源:igfitidea点击:

"synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'." problem in TensorFlow

pythonpython-3.xnumpytensorflowartificial-intelligence

提问by Emilijus052

I installed TensorFlow 1.10.1 but when I tried to import TensorFlow it said that I need TensorFlow version 1.10.0. Thus, I installed it and now I get the following warnings:

我安装了 TensorFlow 1.10.1,但是当我尝试导入 TensorFlow 时,它说我需要 TensorFlow 1.10.0 版。因此,我安装了它,现在我收到以下警告:

>>> import tensorflow
C:\Users\PC\Anaconda3\envs\tut\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)])
C:\Users\PC\Anaconda3\envs\tut\lib\site-packages\tensorflow\python\framework\dtypes.py:517: 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_quint8 = np.dtype([("quint8", np.uint8, 1)])
C:\Users\PC\Anaconda3\envs\tut\lib\site-packages\tensorflow\python\framework\dtypes.py:518: 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_qint16 = np.dtype([("qint16", np.int16, 1)])
C:\Users\PC\Anaconda3\envs\tut\lib\site-packages\tensorflow\python\framework\dtypes.py:519: 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_quint16 = np.dtype([("quint16", np.uint16, 1)])
C:\Users\PC\Anaconda3\envs\tut\lib\site-packages\tensorflow\python\framework\dtypes.py:520: 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_qint32 = np.dtype([("qint32", np.int32, 1)])
C:\Users\PC\Anaconda3\envs\tut\lib\site-packages\tensorflow\python\framework\dtypes.py:525: 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_resource = np.dtype([("resource", np.ubyte, 1)])
C:\Users\PC\Anaconda3\envs\tut\lib\site-packages\tensorboard\compat\tensorflow_stub\dtypes.py:541: 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)])
C:\Users\PC\Anaconda3\envs\tut\lib\site-packages\tensorboard\compat\tensorflow_stub\dtypes.py:542: 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_quint8 = np.dtype([("quint8", np.uint8, 1)])
C:\Users\PC\Anaconda3\envs\tut\lib\site-packages\tensorboard\compat\tensorflow_stub\dtypes.py:543: 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_qint16 = np.dtype([("qint16", np.int16, 1)])
C:\Users\PC\Anaconda3\envs\tut\lib\site-packages\tensorboard\compat\tensorflow_stub\dtypes.py:544: 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_quint16 = np.dtype([("quint16", np.uint16, 1)])
C:\Users\PC\Anaconda3\envs\tut\lib\site-packages\tensorboard\compat\tensorflow_stub\dtypes.py:545: 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_qint32 = np.dtype([("qint32", np.int32, 1)])
C:\Users\PC\Anaconda3\envs\tut\lib\site-packages\tensorboard\compat\tensorflow_stub\dtypes.py:550: 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_resource = np.dtype([("resource", np.ubyte, 1)])

采纳答案by Anubhav Singh

It just a warning, not an error. It occurring because your current numpy libray version is not compatible with tensorflow version. You need to downgrade numpy version.

它只是一个警告,而不是一个错误。这是因为您当前的 numpy libray 版本与 tensorflow 版本不兼容。您需要降级 numpy 版本。

tensorflow 1.10.0has requirement numpy<=1.14.5,>=1.13.3, but you must have some higher version installed(this warning message occurs with newest numpy version 1.17.0).

tensorflow 1.10.0有要求numpy<=1.14.5,>=1.13.3,但您必须安装一些更高版本(此警告消息出现在最新的 numpy 版本 1.17.0 中)。

回答by adhg

If you're using TF 2.0 a quick solution would be to downgrade your numpyto 1.16.4. (I used 1.17 and received the same warning messages).

如果您使用的是 TF 2.0,一个快速的解决方案是将您的 numpy 降级到 1.16.4。(我使用 1.17 并收到相同的警告消息)。

1. pip uninstall numpy 
2. pip install numpy==1.16.4

See here(thanks to ymodak)

这里(感谢 ymodak)

回答by Chandan Gupta

pip install "numpy<1.17"

To revert to Numpy version 1.16.4

恢复到 Numpy 1.16.4

回答by hpaulj

The newest numpy release notes (1.17) has:

最新的 numpy 发行说明(1.17)有:

Future Changes

Shape-1 fields in dtypes won't be collapsed to scalars in a future version
Currently, a field specified as [(name, dtype, 1)] or "1type" is interpreted 
as a scalar field (i.e., the same as [(name, dtype)] or [(name, dtype, ()]). 
This now raises a FutureWarning; in a future version, it will be interpreted 
as a shape-(1,) field, i.e. the same as [(name, dtype, (1,))] or "(1,)type" 
(consistently with [(name, dtype, n)] / "ntype" with n>1, which is already 
equivalent to [(name, dtype, (n,)] / "(n,)type").

https://docs.scipy.org/doc/numpy/release.html

https://docs.scipy.org/doc/numpy/release.html

Thus with your expression:

因此用你的表达:

In [123]: np.dtype([("qint8", np.int8, 1)])                                                                  
/usr/local/bin/ipython3:1: 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'.
  #!/usr/bin/python3
Out[123]: dtype([('qint8', 'i1')])

In [124]: np.dtype([("qint8", np.int8, (1,))])                                                               
Out[124]: dtype([('qint8', 'i1', (1,))])

In [125]: np.dtype([("qint8", np.int8)])                                                                     
Out[125]: dtype([('qint8', 'i1')])

In [126]: np.dtype([("qint8", np.int8, 2)])                                                                  
Out[126]: dtype([('qint8', 'i1', (2,))])

In [127]: np.__version__                                                                                     
Out[127]: '1.17.0'

回答by Sami_c137

I had the same problem in my linux laptop with tensorflow in python3 v3.6

我的 linux 笔记本电脑在 python3 v3.6 中使用 tensorflow 时遇到了同样的问题

Actually, you just need to change some lines in 2 files :

实际上,您只需要更改 2 个文件中的一些行:

  • 1

    ~/.local/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py

  • 1

    ~/.local/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py

in your case :

在你的情况下:

C:\Users\PC\Anaconda3\envs\tut\lib\site-packages\tensorflow\python\framework\dtypes.py



now change this code : (line 516)



现在更改此代码:(第 516 行)

_np_qint8 = np.dtype([("qint8", np.int8, 1)])
_np_quint8 = np.dtype([("quint8", np.uint8, 1)])
_np_qint16 = np.dtype([("qint16", np.int16, 1)])
_np_quint16 = np.dtype([("quint16", np.uint16, 1)])
_np_qint32 = np.dtype([("qint32", np.int32, 1)])


# _np_bfloat16 is defined by a module import.

# Custom struct dtype for directly-fed ResourceHandles of supported type(s).
np_resource = np.dtype([("resource", np.ubyte, 1)])

by this code :

通过此代码:

_np_qint8 = np.dtype([("qint8", np.int8, (1,))])
_np_quint8 = np.dtype([("quint8", np.uint8, (1,))])
_np_qint16 = np.dtype([("qint16", np.int16, (1,))])
_np_quint16 = np.dtype([("quint16", np.uint16, (1,))])
_np_qint32 = np.dtype([("qint32", np.int32, (1,))])

# _np_bfloat16 is defined by a module import.

# Custom struct dtype for directly-fed ResourceHandles of supported type(s).
np_resource = np.dtype([("resource", np.ubyte, (1,))])

you have to do the same on this file :

你必须在这个文件上做同样的事情:

  • 2

    ~/.local/lib/python3.6/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py

  • 2

    ~/.local/lib/python3.6/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py

in your case :

在你的情况下:

C:\Users\PC\Anaconda3\envs\tut\lib\site-packages\tensorboard/compat/tensorflow_stub/dtypes.py

and it will work.

它会起作用。

回答by Amit Rautray

It is happening because of your TensorFlow version is incompatible with numpy. Try reinstalling numpy's previous versions. In my case I tried 1.16.4 : pip install numpy==1.16.4

这是因为您的 TensorFlow 版本与 numpy 不兼容。尝试重新安装 numpy 以前的版本。就我而言,我尝试了 1.16.4 : pip install numpy==1.16.4

But first, you need to shutdown all running kernals and uninstall numpy with : pip uninstall numpy

但首先,您需要关闭所有正在运行的内核并使用以下命令卸载 numpy:pip uninstall numpy