ModuleNotFoundError:没有名为'tensorflow.examples'的模块

时间:2018-05-13 06:40:45

标签: python tensorflow mnist

当我导入tensorflow

import tensorflow as tf

我没有收到错误。但是,我确实得到以下错误。如果有帮助,我正在使用spyder。

根据其他问题,我使用conda和pip安装确保了最新(v1.8)tensorflow。这并没有解决问题。请协助。

import tensorflow.examples.tutorials.mnist.input_data as input_data

ModuleNotFoundError: No module named 'tensorflow.examples'

11 个答案:

答案 0 :(得分:2)

有时TensorFlow示例未预下载,因此您可能需要运行以下命令以使用以下代码从Github安装示例。

!pip install -q git+https://github.com/tensorflow/examples.git

答案 1 :(得分:2)

我通过在**tutorial**中添加tensorflow_core目录来解决此问题,通常在缺少此文件时会弹出此问题

  1. ..\anaconda3\envs\tensorflow\Lib\site-packages\tensorflow_core\examples检查此目录以查看是否具有tutorials文件。 lack of tutorial file
  2. 如果没有,请转到https://github.com/tensorflow/tensorflow下载zip文件,然后解压缩所有文件(或将其打开)。 download tutorial file
  3. tensorflow-master\tensorflow\examples\查找教程文件,并将其复制到..\anaconda3\envs\tensorflow\Lib\site-packages\tensorflow_core\examples
  4. 问题已解决。 run
from tensorflow.examples.tutorials.mnist import input_data
import matplotlib.pyplot as plt
mnist = input_data.read_data_sets("MNIST_data", one_hot=True)
im = mnist.train.images[1]
im = im.reshape(-1, 28)
plt.imshow(im)

答案 2 :(得分:2)

要在Tensorflow 2.0中加载mnist数据集,请执行以下操作:

mnist = tf.keras.datasets.mnist

(x_train, y_train), (x_test, y_test) = mnist.load_data()

这里是参考: TensorFlow 2 quickstart for beginners

另一种方法(也适用于本地保存的数据集):

DATA_URL = 'https://storage.googleapis.com/tensorflow/tf-keras-datasets/mnist.npz'

path = tf.keras.utils.get_file('mnist.npz', DATA_URL)
with np.load(path) as data:
  train_examples = data['x_train']
  train_labels = data['y_train']
  test_examples = data['x_test']
  test_labels = data['y_test']

这里是参考: Load NumPy data

答案 3 :(得分:1)

使用以下命令,它将下载数据。来自tensorflow documentation

import tensorflow as tf
(train_images, train_labels), (test_images, test_labels) = tf.keras.datasets.mnist.load_data()

答案 4 :(得分:1)

不同方法 操作系统:Windows

从以下位置复制:

https://github.com/tensorflow/examples/tree/master/tensorflow_examples

[python文件夹] \ Lib \ site-packages \ tensorflow_examples

使用

import tensorflow_examples

示例

from tensorflow_examples.models import pix2pix

但用于数据集:

pip install tensorflow_datasets

答案 5 :(得分:0)

有时在下载TF时,示例目录可能不可用。你可以通过链接'示例来纠正它。目录从GitHub repo进入tensorflow python wheel文件夹。这样您就不需要更改代码。

如果这不起作用,请尝试将import tensorflow.examples.tutorials.mnist.input_data as input_data替换为import input_data,如链接中所述: TensorFlow MNIST example not running with fully_connected_feed.py

希望这有帮助!!!

答案 6 :(得分:0)

我在Mac上解决了此问题,只需将官方示例复制到tensorflow_core / examples目录。

  1. 拉张量流代码

    git clone https://github.com/tensorflow/tensorflow

  2. 将示例复制到系统python3目录

    cp -a tensorflow/examples/ /usr/local/lib/python3.7/site-packages/tensorflow_core/examples/

答案 7 :(得分:0)

我认为您应该在tensorflow 2上使用波纹管

import tensorflow_datasets
mnist = tensorflow_datasets.load('mnist')

答案 8 :(得分:0)

您需要下载数据集才能使用它。

命令:

pip install tensorflow-datasets

代码部分:

mnist_train = tfds.load(name="mnist", split="train")

您已完成。祝您编码愉快! :)

答案 9 :(得分:0)

您只需要下载丢失的文件并将其复制到tensorflow-core /示例中即可。

在Windows 10上对我来说

是: C:\ Users \ Amirreza \ AppData \ Local \ Programs \ Python \ Python37 \ Lib \ site-packages \ tensorflow_core \ examples

答案 10 :(得分:-1)

如果您使用anaconda,则需要使用conda install tensorflow安装完整的tensorflow'

相关问题