"synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'." problem in TensorFlow
Question:
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:
>>> import tensorflow
C:UsersPCAnaconda3envstutlibsite-packagestensorflowpythonframeworkdtypes.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:UsersPCAnaconda3envstutlibsite-packagestensorflowpythonframeworkdtypes.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:UsersPCAnaconda3envstutlibsite-packagestensorflowpythonframeworkdtypes.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:UsersPCAnaconda3envstutlibsite-packagestensorflowpythonframeworkdtypes.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:UsersPCAnaconda3envstutlibsite-packagestensorflowpythonframeworkdtypes.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:UsersPCAnaconda3envstutlibsite-packagestensorflowpythonframeworkdtypes.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:UsersPCAnaconda3envstutlibsite-packagestensorboardcompattensorflow_stubdtypes.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:UsersPCAnaconda3envstutlibsite-packagestensorboardcompattensorflow_stubdtypes.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:UsersPCAnaconda3envstutlibsite-packagestensorboardcompattensorflow_stubdtypes.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:UsersPCAnaconda3envstutlibsite-packagestensorboardcompattensorflow_stubdtypes.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:UsersPCAnaconda3envstutlibsite-packagestensorboardcompattensorflow_stubdtypes.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:UsersPCAnaconda3envstutlibsite-packagestensorboardcompattensorflow_stubdtypes.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)])
Answers:
The newest numpy release notes (1.17) has:
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
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'
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.
tensorflow 1.10.0
has 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).
If you’re using TF 2.0 a quick solution would be to downgrade your numpy to 1.16.4. (I used 1.17 and received the same warning messages).
1. pip uninstall numpy
2. pip install numpy==1.16.4
See here (thanks to ymodak)
pip install "numpy<1.17"
To revert to Numpy version 1.16.4
I had the same problem in my linux laptop with tensorflow in python3 v3.6
Actually, you just need to change some lines in 2 files :
-
1
~/.local/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py
in your case :
C:UsersPCAnaconda3envstutlibsite-packagestensorflowpythonframeworkdtypes.py
now change this code : (line 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
in your case :
C:UsersPCAnaconda3envstutlibsite-packagestensorboard/compat/tensorflow_stub/dtypes.py
and it will work.
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
But first, you need to shutdown all running kernals and uninstall numpy with :
pip uninstall numpy
Or, one could just silence the warning:
import warnings
warnings.simplefilter(action='ignore', category=FutureWarning)
import tensorflow as tf
This approach was suggested here: How to suppress Pandas Future warning ?
Do you have multiple versions of numpy installed or have a new numpy version that is not compatible with tensorflow?
>pip show numpy
or
import tensorflow as tf
print(tf.__version__)
import numpy as np
print(np.__version__)
Downgrading numpy version from >1.17 to 1.16.4 will resolve issue with Tensorflow 1.14.0
How to downgrade numpy?
pip uninstall numpy # (till you uninstall all versions)
pip install numpy==1.16.4
After that you can check the copatibility:
After that, please restart your runtime and execute below code
import tensorflow as tf
print(tf.__version__)
import numpy as np
print(np.__version__)
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:
>>> import tensorflow
C:UsersPCAnaconda3envstutlibsite-packagestensorflowpythonframeworkdtypes.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:UsersPCAnaconda3envstutlibsite-packagestensorflowpythonframeworkdtypes.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:UsersPCAnaconda3envstutlibsite-packagestensorflowpythonframeworkdtypes.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:UsersPCAnaconda3envstutlibsite-packagestensorflowpythonframeworkdtypes.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:UsersPCAnaconda3envstutlibsite-packagestensorflowpythonframeworkdtypes.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:UsersPCAnaconda3envstutlibsite-packagestensorflowpythonframeworkdtypes.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:UsersPCAnaconda3envstutlibsite-packagestensorboardcompattensorflow_stubdtypes.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:UsersPCAnaconda3envstutlibsite-packagestensorboardcompattensorflow_stubdtypes.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:UsersPCAnaconda3envstutlibsite-packagestensorboardcompattensorflow_stubdtypes.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:UsersPCAnaconda3envstutlibsite-packagestensorboardcompattensorflow_stubdtypes.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:UsersPCAnaconda3envstutlibsite-packagestensorboardcompattensorflow_stubdtypes.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:UsersPCAnaconda3envstutlibsite-packagestensorboardcompattensorflow_stubdtypes.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)])
The newest numpy release notes (1.17) has:
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
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'
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.
tensorflow 1.10.0
has 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).
If you’re using TF 2.0 a quick solution would be to downgrade your numpy to 1.16.4. (I used 1.17 and received the same warning messages).
1. pip uninstall numpy
2. pip install numpy==1.16.4
See here (thanks to ymodak)
pip install "numpy<1.17"
To revert to Numpy version 1.16.4
I had the same problem in my linux laptop with tensorflow in python3 v3.6
Actually, you just need to change some lines in 2 files :
-
1
~/.local/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py
in your case :
C:UsersPCAnaconda3envstutlibsite-packagestensorflowpythonframeworkdtypes.py
now change this code : (line 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
in your case :
C:UsersPCAnaconda3envstutlibsite-packagestensorboard/compat/tensorflow_stub/dtypes.py
and it will work.
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
But first, you need to shutdown all running kernals and uninstall numpy with :
pip uninstall numpy
Or, one could just silence the warning:
import warnings
warnings.simplefilter(action='ignore', category=FutureWarning)
import tensorflow as tf
This approach was suggested here: How to suppress Pandas Future warning ?
Do you have multiple versions of numpy installed or have a new numpy version that is not compatible with tensorflow?
>pip show numpy
or
import tensorflow as tf
print(tf.__version__)
import numpy as np
print(np.__version__)
Downgrading numpy version from >1.17 to 1.16.4 will resolve issue with Tensorflow 1.14.0
How to downgrade numpy?
pip uninstall numpy # (till you uninstall all versions)
pip install numpy==1.16.4
After that you can check the copatibility:
After that, please restart your runtime and execute below code
import tensorflow as tf
print(tf.__version__)
import numpy as np
print(np.__version__)