【问题标题】:How to run python code without the tensorflow warning如何在没有 tensorflow 警告的情况下运行 python 代码
【发布时间】:2019-09-21 11:53:49
【问题描述】:

我在 Windows 10 上使用 python 3.6.9 和 tensorflow 1.14.0,并在 python 3.6 上安装和更新了所有库。当我运行我的代码时,我希望它只打印出 json 数据,但我得到一个很大的 tensorflow/tflearn 错误,我不知道为什么。

我的代码:

import nltk
import numpy
import tflearn
import tensorflow
import random
import json

from nltk.stem.lancaster import LancasterStemmer
stemmer = LancasterStemmer()


with open("intents.json") as file:
    data = json.load(file)

print(data)

我得到的错误:

C:\Users\PC\PycharmProjects\Machine Learning\venv\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\PycharmProjects\Machine Learning\venv\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\PycharmProjects\Machine Learning\venv\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\PycharmProjects\Machine Learning\venv\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\PycharmProjects\Machine Learning\venv\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\PycharmProjects\Machine Learning\venv\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\PycharmProjects\Machine Learning\venv\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\PycharmProjects\Machine Learning\venv\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\PycharmProjects\Machine Learning\venv\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\PycharmProjects\Machine Learning\venv\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\PycharmProjects\Machine Learning\venv\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\PycharmProjects\Machine Learning\venv\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)])
WARNING:tensorflow:From C:\Users\PC\PycharmProjects\Machine Learning\venv\lib\site-packages\tflearn\helpers\summarizer.py:9: The name tf.summary.merge is deprecated. Please use tf.compat.v1.summary.merge instead.

WARNING:tensorflow:From C:\Users\PC\PycharmProjects\Machine Learning\venv\lib\site-packages\tflearn\helpers\trainer.py:25: The name tf.summary.FileWriter is deprecated. Please use tf.compat.v1.summary.FileWriter instead.

WARNING:tensorflow:From C:\Users\PC\PycharmProjects\Machine Learning\venv\lib\site-packages\tflearn\collections.py:13: The name tf.GraphKeys is deprecated. Please use tf.compat.v1.GraphKeys instead.

WARNING:tensorflow:From C:\Users\PC\PycharmProjects\Machine Learning\venv\lib\site-packages\tflearn\config.py:123: The name tf.get_collection is deprecated. Please use tf.compat.v1.get_collection instead.

WARNING:tensorflow:From C:\Users\PC\PycharmProjects\Machine Learning\venv\lib\site-packages\tflearn\config.py:129: The name tf.add_to_collection is deprecated. Please use tf.compat.v1.add_to_collection instead.

WARNING:tensorflow:From C:\Users\PC\PycharmProjects\Machine Learning\venv\lib\site-packages\tflearn\config.py:131: The name tf.assign is deprecated. Please use tf.compat.v1.assign instead.

我该怎么做才能消除该错误并正确运行我的代码?

【问题讨论】:

    标签: python-3.x tensorflow tflearn


    【解决方案1】:

    试试这些命令:

    pip install tensorflow==1.14.0
    
    pip install numpy==1.16.4
    

    【讨论】:

      【解决方案2】:

      Numpy 将弃用某些 API。请参阅release note

      dtypes 中的 Shape-1 字段在未来版本中不会折叠为标量

      目前,指定为 [(name, dtype, 1)] 或 "1type" 的字段被解释为标量字段(即,与 [(name, dtype)] 或 [(name, dtype, () ]). 现在会引发 FutureWarning;在未来的版本中,它将被解释为 shape-(1,) 字段,即与 [(name, dtype, (1,))] 或 "(1,) type"(与 [(name, dtype, n)] / "ntype" 一致,其中 n>1,这已经等价于 [(name, dtype, (n,)] / "(n,)type")。

      但是您的 tensorflow 版本使用 [(name, dtype, 1)] 并导致弃用警告。由于它是警告,您可以忽略,以后的tensorflow 版本或最新版本会处理此警告。

      这已在tensorflowsee this 中实现。请将包更新到最新,它会解决我认为的问题。

      另一件事是tflearn 包也有不推荐使用的命令。它再次在tensorflow 包中使用,但由于tflearn 包最近不活动,我认为您必须忽略此警告,这将无法解决。见the repository

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-03
      • 2021-07-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-24
      • 1970-01-01
      • 2013-11-20
      相关资源
      最近更新 更多