Tensorflow: FutureWarning: Deprecated numpy API calls in tf.python.framework.dtypes

Created on 5 Jul 2019  路  33Comments  路  Source: tensorflow/tensorflow

System information

  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow): not really
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): MacOS Mojave 10.14.5 (18F132)
  • TensorFlow installed from (source or binary): tensorflow==2.0.0b1 from https://pypi.org/
  • TensorFlow version (use command below): v2.0.0-beta0-16-g1d91213fe7 2.0.0-beta1
  • Python version: Python 3.6.8
  • Bazel version (if compiling from source): N/A
  • GCC/Compiler version (if compiling from source): N/A
  • CUDA/cuDNN version: N/A
  • GPU model and memory: N/A

Describe the current behavior

A plenty of FutureWarning errors:

/xxx/venv/lib/python3.6/site-packages/tensorflow-2.0.0b1-py3.6-macosx-10.14-x86_64.egg/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)])
/xxx/venv/lib/python3.6/site-packages/tensorflow-2.0.0b1-py3.6-macosx-10.14-x86_64.egg/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)])
/xxx/venv/lib/python3.6/site-packages/tensorflow-2.0.0b1-py3.6-macosx-10.14-x86_64.egg/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)])
/xxx/venv/lib/python3.6/site-packages/tensorflow-2.0.0b1-py3.6-macosx-10.14-x86_64.egg/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)])
/xxx/venv/lib/python3.6/site-packages/tensorflow-2.0.0b1-py3.6-macosx-10.14-x86_64.egg/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)])
/xxx/venv/lib/python3.6/site-packages/tensorflow-2.0.0b1-py3.6-macosx-10.14-x86_64.egg/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)])
/xxx/venv/lib/python3.6/site-packages/tb_nightly-1.14.0a20190603-py3.6.egg/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)])
/xxx/venv/lib/python3.6/site-packages/tb_nightly-1.14.0a20190603-py3.6.egg/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)])
/xxx/venv/lib/python3.6/site-packages/tb_nightly-1.14.0a20190603-py3.6.egg/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)])
/xxx/venv/lib/python3.6/site-packages/tb_nightly-1.14.0a20190603-py3.6.egg/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)])
/xxx/venv/lib/python3.6/site-packages/tb_nightly-1.14.0a20190603-py3.6.egg/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)])
/xxx/venv/lib/python3.6/site-packages/tb_nightly-1.14.0a20190603-py3.6.egg/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)])

Describe the expected behavior

No warnings.

Code to reproduce the issue

import tensorflow.python.framework.dtypes

print("Hello world")
TF 2.0 apis awaiting response support

Most helpful comment

@Akeaakar And for the time being, pip install "numpy<1.17" to revert to numpy version 1.16.4

All 33 comments

@habernal We have executed your code in Google colab and in Jupyter notebook with TF version
2.0 beta 1 and numpy version 1.16.4.We did not get any warnings.Please upgrade your numpy version and check whether the warnings still persists.Thanks!

Thanks, @ravikyram - I've double-checked the installed libraries and found the culprit.

TF 2.0.b1 comes with numpy dependency 1.16.4 and it shows no warning. So it is correct you couldn't reproduce the bug, neither could I.

However, it turned out that I had numpy 1.17.0rc1 installed in the project (no idea from which library it was linked as I certainly didn't install it by hand).

Numpy 1.17.0rc1 is responsible for complaining about these FutureWarnings. Perhaps not urgent to fix for now but once there is an upgrade to np 17, this will show up again, I guess.

In fact, the numpy dependency is treated differently given the tool you install TF (pip versus setuptools). Both tested in a clean virtual environment with only these libraries installed at the beginning:

pip==19.1.1 setuptools==41.0.1 wheel==0.33.4

  1. Installing TF using pip:
$ pip install tensorflow==2.0.0b1 --no-cache-dir
...
Collecting numpy<2.0,>=1.14.5 (from tensorflow==2.0.0b1)
  Downloading https://files.pythonhosted.org/packages/...cc/numpy-1.16.4-cp36-cp....whl (13.9MB)
...
  1. Installing TF as dependendy in setup.py containing only:
from setuptools import setup
setup(
    name='tf30427',
    version='0.0.1',
    install_requires=['tensorflow==2.0.0b1'],
)

and then installing as

$ python setup.py install
...
Searching for numpy<2.0,>=1.14.5
Reading https://pypi.org/simple/numpy/
Downloading https://files.pythonhosted.org/packages/e...17/numpy-1.17.0rc1-cp36-cp36...25e0
Best match: numpy 1.17.0rc1
Processing numpy-1.17.0rc1-cp36-cp36m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
Installing numpy-1.17.0rc1-cp36-cp36m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl to /xxx/venv/lib/python3.6/site-packages
Adding numpy 1.17.0rc1 to easy-install.pth file
...

They understand the requirement numpy<2.0,>=1.14.5 differently: pip installs 1.16.4 while setuptools 1.17.0rc1.

Proposed fix:

Change the dependency to numpy<1.17,>=1.14.5 to stick with the 1.16 version regardless of the installation procedure.

And here's the core of the problem: https://github.com/pypa/setuptools/issues/855

as discovered by others, too: https://stackoverflow.com/q/54796975

@habernal let me know if we can close this issue since we found the solution. Thanks!

@habernal I think tensorflow could be updated to make it compatible with numpy 1.17+. Created a PR #30559 for the fix.

Hello i am having the same error. Can u plese tell me what to do with instruction to solve this problem.Thanks

@Akeaakar The issue has been fixed and merged into the master branch. In the next release of TF the issue should be gone.

@Akeaakar And for the time being, pip install "numpy<1.17" to revert to numpy version 1.16.4

With Ubuntu19.04, the combination of tensorflow-gpu 1.14.0 (or tensorflow-gpu 1.12.2) with numpy 1.17.0 has the same warnings as well. When change numpy version to 1.16.3, the warnings are gone.

Or you can supress the warnings using the below code.

import warnings
import tensorflow as tf

warnings.filterwarnings('ignore')

Or you can supress the warnings using the below code.

import warnings
import tensorflow as tf

warnings.filterwarnings('ignore')

seems this doesn't work for me. (numpy1.17.0 python3.7.3)

Or you can supress the warnings using the below code.

import warnings
import tensorflow as tf

warnings.filterwarnings('ignore')

seems this doesn't work for me. (numpy1.17.0 python3.7.3)

import warnings
warnings.filterwarnings('ignore',category=FutureWarning)
import tensorflow as tf

Needs to be before the import, since that is where the warnings are coming from. Also added a restriction to only effect that warning category instead of silencing all warnings.

import warnings
warnings.filterwarnings('ignore',category=FutureWarning)
import tensorflow as tf
It works for me even under a virtual environment

I have numpy in ./venv/lib/python3.7/site-packages (1.17.2). In both Jupyter and VS Code, I get the idea. I really dislike the idea of ignoring the warning. Any fixes would be greatly appreciated.

pip install "numpy<1.17"

After doing that, system installed numpy-1.16.5. But now import tensorflow says:
ImportError: Something is wrong with the numpy installation.

numpy: pip install --upgrade numpy
keras: conda install -c conda-forge keras

Upgrade your numpy and install keras by using the above command in Anaconda prompt.

Hi, for reference, I got this fixed with these 2 version:

>>> import tensorflow as tf
>>> print(tf.__version__)
2.0.0-rc1
>>> import numpy as np
>>> print(np.__version__)
1.17.2
>>> exit()

09/24/19, hope this helps

Thanks @Namburger . The warnings are gone on 2.0.0-rc1.

With the latest release of tensorflow (i.e., 2.0.0) and numpy 1.17.2, the warning is back.

Can you provide a reproducer, @UndeadKernel ? I cannot reproduce:

>>> import tensorflow as tf
>>> tf.__version__
'2.0.0'
>>> import numpy as np
>>> np.__version__
'1.17.2'
>>> import tensorflow.python.framework.dtypes
>>> 

Also tried from a file:

import tensorflow as tf
import numpy as np

print("TF", tf.__version__)
print("NP", np.__version__)

import tensorflow.python.framework.dtypes

but no warnings:

(gh_numpty) mihaimaruseac@ankh:/tmp/gh_numpty$ python test.py 
TF 2.0.0
NP 1.17.2

@mihaimaruseac, I can reproduce the problem with both examples of yours. That is, I see the following output:

2019-10-14 12:20:56.438892: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.1
/usr/lib/python3.7/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)])
/usr/lib/python3.7/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)])
/usr/lib/python3.7/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)])
/usr/lib/python3.7/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)])
/usr/lib/python3.7/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)])
/usr/lib/python3.7/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)])
TF 2.0.0
NP 1.17.2

I'm using arch. Arch, if I recall correctly, adapts Tensorflow to work with Python 3.7.4. Or is this version of Python already supported by Tensorflow?

@UndeadKernel I'm running Arch too, but I'm not getting any warnings as of now (they were present earlier). My packages are:

  • python-tensorflow-opt-cuda: 2.0.0-2
  • python-numpy-openblas: 1.17.2-1

This is indeed quite strange @rharish101, I have the same exact versions. I tried using python-numpy from the official repo and python-numpy-openblas` from the AUR and I see the same FutureWarning messages.

@UndeadKernel Could you try reinstalling the TensorFlow package? It might have changed in the latest patch (2.0.0-2 as opposed to 2.0.0-1). I remember that I, too, saw those warnings in the last few days, but as of today, they are gone, with the only difference that I updated TensorFlow 9 days ago.

@rharish101, thank for the suggestion.
I noticed that tensorboard was not the same version as tensorflow. After reinstalling tensorboard (notice that this is "tensorBoard" and not "TensorFlow"), the warning went away.

There is an official release of 2.0, you should not need to use the patched versions.

To which patches are you referring @mihaimaruseac?

2.0.0-1 and 2.0.0-2 mentioned in above comments

pip install tensorflow==2.0.0 should work (might need to upgrade pip to the latest version if you're on an old one, due to the change to be manylinux2010 compliant)

try

pip3 [pip] install tf-nightly

the nightly build of tensorflow seems to have that problem sorted out, best of luck

for tensorflow==2.0.0 and numpy==1.17.4

I don't get the error/warning.

You can try as:

>>> import tensorflow as tf
>>> tf.__version__
'2.0.0'
>>> import numpy as np
>>> np.__version__
'1.17.4'
>>> import tensorflow.python.framework.dtypes
>>>

@Akeaakar And for the time being, pip install "numpy<1.17" to revert to numpy version 1.16.4

And also for anaconda:
conda install "numpy<1.17"

And for the time being, pip install "numpy<1.17" to revert to numpy version 1.16.4

After how many hours this was the one that solved my problem. I installed the TF that had the numpy version installed (18.0) and when i reverted it to 1.16.4 it works! thanks

Was this page helpful?
0 / 5 - 0 ratings