ModuleNotFoundError: No module named 'tensorflow.examples'

独自空忆成欢 提交于 2020-06-27 08:53:15

问题


When I import tensorflow

import tensorflow as tf

I don't get an error. However, I do get the error below. I'm using spyder if that helps.

As per other questions, I ensured up to date (v1.8) tensorflow using both conda and then pip installs. This didn't resolve the issue. Please assist.

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

ModuleNotFoundError: No module named 'tensorflow.examples'

回答1:


Sometimes on downloading the TF, the example directory might not be available. You could rectify it by linking the 'example' directory from the GitHub repo into the tensorflow python wheel folder. That way you don't need to change the code.

If this doesn't work, try to replace import tensorflow.examples.tutorials.mnist.input_data as input_data as import input_data as mentioned in the link: TensorFlow MNIST example not running with fully_connected_feed.py

Hope this helps!!!




回答2:


Sometimes the TensorFlow examples are not pre-downloaded, so you might need to run the below command to install the examples from Github using the below code.

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



回答3:


Use the following, it will download the data. It is from the tensorflow documentation

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



回答4:


I solved this issue by adding **tutorial** directory into tensorflow_core, usually this issue pops up when lacking of this file

  1. ..\anaconda3\envs\tensorflow\Lib\site-packages\tensorflow_core\examples check this directory to see if you have tutorials file. lack of tutorial file
  2. If you do not have, then go to https://github.com/tensorflow/tensorflow download the zip file, and extract all (or open it). download tutorial file
  3. find tutorials file from tensorflow-master\tensorflow\examples\, and copy it to ..\anaconda3\envs\tensorflow\Lib\site-packages\tensorflow_core\examples.
  4. Issue resolved. 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)




回答5:


I think you should use like bellow on tensorflow 2

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



回答6:


To load the mnist dataset in Tensorflow 2.0:

mnist = tf.keras.datasets.mnist

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

Here is the reference: TensorFlow 2 quickstart for beginners

Another method(also works for locally saved dataset):

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

Here is the reference: Load NumPy data




回答7:


I solved this issue on Mac, simply copy the official examples to tensorflow_core/examples directory.

  1. pull the tensorflow code

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

  2. copy the examples to the system python3 directory

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




回答8:


You need to download the data sets to use it.

Command:

pip install tensorflow-datasets

Code part:

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

You are done now. Happy coding! :)




回答9:


Different approach OS: Windows

copy from:

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

to

[python folder]\Lib\site-packages\tensorflow_examples

use

import tensorflow_examples

example

from tensorflow_examples.models import pix2pix

but for datasets use:

pip install tensorflow_datasets



回答10:


if you use anaconda, you need intall tensorflow with conda install tensorflow'



来源:https://stackoverflow.com/questions/50313441/modulenotfounderror-no-module-named-tensorflow-examples

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!