Skip to content

[Solved] 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)])

Tensorflow can be said to be the most well-known among the many deep learning framework, but when I use Keras/Tensorflow, I often encounter the following FutureWarning about the Numpy version:

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)])


Although the program is running smoothly, every time I see this error report when training the model, it will pop up for the first time, and I feel quite tired in the long run.

Today I decided to write this article to figure out the cause of this problem, and secondly to resolve this warning.


Cause of the problem

The reason for this problem is simple: the version of Numpy is higher than 1.17.x. From the error message, it seems that whether it is Keras or Tensorflow (or Tensorflow called behind Keras), when using Numpy, they will use (type, 1) or '1type'.

However, this way of writing may be in it will be replaced in later versions of Numpy.

In other words, if the Tensorflow version has not been updated, but the Numpy version is continuously updated, one day an error will be reported because of these code.

But don’t worry too much, because the Library used in a framework has version restrictions. When you accidentally report an error, check it online and someone will always share the applicable version.

Finally, by the way, Tensorflow has certainly noticed that the Numpy version may need to change the way the code is written. According to my actual measurement, in Tensorflow version 2.2.0 and above, using the latest version of Numpy will not have this error. Obviously Tensorflow has also been changed in subsequent versions.

But generally speaking, upgrading the Tensorflow version to solve this problem seems to be a very strange way… After all, Tensorflow is the main framework to be used, and many functions are different between different versions. Therefore, there are only two ways to solve this Warning as described below:

  1. Change Numpy version
  2. Use warnings module to hide warning

Solutions

1. Change Numpy version

As mentioned above, this problem is because when Numpy is version 1.17.x or higher, if the program uses the old writing method, it can still be executed, but Numpy will throw a warning to tell you that the next version may be replaced. This way of writing.

So the solution is to install a different version of Numpy.

pip3 install numpy==1.16.0


This will make the warning disappear. However, if it will affect your model training task, please refer to the second solution.


2. Use warnings module to hide warning

This method is also very simple, just add the following program at the beginning of the program.

import warnings
warnings.filterwarnings('ignore')


But it should be noted that if there are other warning messages during program development, they may also be blocked.


3. Ignore this warning…

The third method of the hidden version! Adjust your mentality and tell yourself that warning is equivalent to not reporting an error! There is no side-effect solution at all, and there is no need to change the version or add code.


References


Read More

Leave a Reply