警告:请使用tensorflow / models中的官方/ mnist / dataset.py等替代方法

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了警告:请使用tensorflow / models中的官方/ mnist / dataset.py等替代方法相关的知识,希望对你有一定的参考价值。

我正在使用Tensorflow做一个简单的教程,我刚刚安装了它应该更新,首先我使用以下代码加载mnist数据:

import numpy as np
import os
from tensorflow.examples.tutorials.mnist import input_data
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'

mnist = input_data.read_data_sets("MNIST_data/", one_hot=True)
train_data = mnist.train.images  # Returns np.array
train_labels = np.asarray(mnist.train.labels, dtype=np.int32)
eval_data = mnist.test.images  # Returns np.array
eval_labels = np.asarray(mnist.test.labels, dtype=np.int32)

但是当我运行它时,我收到以下警告:

WARNING:tensorflow:From C:UsersuserPycharmProjectsTensorFlowRNNvenvlibsite-packages	ensorflowcontriblearnpythonlearndatasetsase.py:198: retry (from tensorflow.contrib.learn.python.learn.datasets.base) is deprecated and will be removed in a future version.
Instructions for updating:
Use the retry module or similar alternatives.
WARNING:tensorflow:From C:/Users/user/PycharmProjects/TensorFlowRNN/sample.py:5: read_data_sets (from tensorflow.contrib.learn.python.learn.datasets.mnist) is deprecated and will be removed in a future version.
Instructions for updating:
Please use alternatives such as official/mnist/dataset.py from tensorflow/models.
WARNING:tensorflow:From C:UsersuserPycharmProjectsTensorFlowRNNvenvlibsite-packages	ensorflowcontriblearnpythonlearndatasetsmnist.py:260: maybe_download (from tensorflow.contrib.learn.python.learn.datasets.base) is deprecated and will be removed in a future version.
Instructions for updating:
Please write your own downloading logic.
WARNING:tensorflow:From C:UsersuserPycharmProjectsTensorFlowRNNvenvlibsite-packages	ensorflowcontriblearnpythonlearndatasetsmnist.py:262: extract_images (from tensorflow.contrib.learn.python.learn.datasets.mnist) is deprecated and will be removed in a future version.
Instructions for updating:
Please use tf.data to implement this functionality.
Extracting MNIST_data/train-images-idx3-ubyte.gz
WARNING:tensorflow:From C:UsersuserPycharmProjectsTensorFlowRNNvenvlibsite-packages	ensorflowcontriblearnpythonlearndatasetsmnist.py:267: extract_labels (from tensorflow.contrib.learn.python.learn.datasets.mnist) is deprecated and will be removed in a future version.
Instructions for updating:
Please use tf.data to implement this functionality.
Extracting MNIST_data/train-labels-idx1-ubyte.gz
WARNING:tensorflow:From C:UsersuserPycharmProjectsTensorFlowRNNvenvlibsite-packages	ensorflowcontriblearnpythonlearndatasetsmnist.py:110: dense_to_one_hot (from tensorflow.contrib.learn.python.learn.datasets.mnist) is deprecated and will be removed in a future version.
Instructions for updating:
Please use tf.one_hot on tensors.
Extracting MNIST_data/t10k-images-idx3-ubyte.gz
Extracting MNIST_data/t10k-labels-idx1-ubyte.gz
WARNING:tensorflow:From C:UsersuserPycharmProjectsTensorFlowRNNvenvlibsite-packages	ensorflowcontriblearnpythonlearndatasetsmnist.py:290: DataSet.__init__ (from tensorflow.contrib.learn.python.learn.datasets.mnist) is deprecated and will be removed in a future version.
Instructions for updating:
Please use alternatives such as official/mnist/dataset.py from tensorflow/models.

我已经使用了os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'这个应该避免获得警告并尝试其他替代方法来获取mnist的行,但总是出现相同的警告,有人可以帮我弄清楚这是不是发生了?

PD:我在Windows 10中使用Python 3.6,以防它有用。

答案

你可以像这样使用tf.logging module

import numpy as np

import tensorflow as tf
old_v = tf.logging.get_verbosity()
tf.logging.set_verbosity(tf.logging.ERROR)

from tensorflow.examples.tutorials.mnist import input_data

mnist = input_data.read_data_sets("MNIST_data/", one_hot=True)
train_data = mnist.train.images  # Returns np.array
train_labels = np.asarray(mnist.train.labels, dtype=np.int32)
eval_data = mnist.test.images  # Returns np.array
eval_labels = np.asarray(mnist.test.labels, dtype=np.int32)

tf.logging.set_verbosity(old_v)
另一答案

tensorflow.examples.tutorials现已弃用,建议使用如下tensorflow.keras.datasets

import tensorflow as tf
mnist = tf.keras.datasets.mnist
(X_train, y_train), (X_test, y_test) = mnist.load_data()

https://www.tensorflow.org/api_docs/python/tf/keras/datasets/mnist/load_data

以上是关于警告:请使用tensorflow / models中的官方/ mnist / dataset.py等替代方法的主要内容,如果未能解决你的问题,请参考以下文章

具有 tensorflow/models/object_detection 的特征金字塔网络

使用 @tffunction 的 Tensorflow2 警告

停止 TensorFlow 打印警告消息

警告:tensorflow:`write_grads` 将在 TensorFlow 2.0 中忽略`TensorBoard` 回调

用于 mac AVX 的 TensorFlow

警告:tensorflow:sample_weight 模式被强制从 ... 到 ['...']