ModulenotFoundError:No模块名为' tensorflow.xamples' (我只是试图加载MNIST)

发布于 2025-01-18 09:37:54 字数 159 浏览 1 评论 0原文

我尝试了很多次,但无论如何都无法使用。

import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_dataput_data

I have tried lots of times by taking many ways but it doesn't work anyway.

import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_dataput_data

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

来日方长 2025-01-25 09:37:55

如果要加载mnist数据集,则可以尝试以下操作:

import tensorflow as tf
import matplotlib.pyplot as plt

(x_train, y_train), (x_test, y_test) = tf.keras.datasets.mnist.load_data()

fig, axes = plt.subplots(2,5,figsize=(15,6))
for idx, axe in enumerate(axes.flatten()):
    axe.axis('off')
    axe.set_title(f'label : {y_train[idx]}')
    axe.imshow(x_train[idx])
plt.show()

或者可以使用tensorflow_datasets喜欢下图:

import tensorflow_datasets as tfds
import matplotlib.pyplot as plt
dataset = tfds.load('mnist', download=True, as_supervised=True, split = 'train').batch(10)
image, label = next(iter(dataset))
fig, axes = plt.subplots(2,5,figsize=(15,6))
for idx, axe in enumerate(axes.flatten()):
    axe.axis('off')
    axe.set_title(f'label : {label[idx]}')
    axe.imshow(image[idx][...,0])
plt.show()

output:

If you want to load MNIST dataset, you can try this:

import tensorflow as tf
import matplotlib.pyplot as plt

(x_train, y_train), (x_test, y_test) = tf.keras.datasets.mnist.load_data()

fig, axes = plt.subplots(2,5,figsize=(15,6))
for idx, axe in enumerate(axes.flatten()):
    axe.axis('off')
    axe.set_title(f'label : {y_train[idx]}')
    axe.imshow(x_train[idx])
plt.show()

Or you can use tensorflow_datasets like below:

import tensorflow_datasets as tfds
import matplotlib.pyplot as plt
dataset = tfds.load('mnist', download=True, as_supervised=True, split = 'train').batch(10)
image, label = next(iter(dataset))
fig, axes = plt.subplots(2,5,figsize=(15,6))
for idx, axe in enumerate(axes.flatten()):
    axe.axis('off')
    axe.set_title(f'label : {label[idx]}')
    axe.imshow(image[idx][...,0])
plt.show()

Output:

enter image description here

你的笑 2025-01-25 09:37:55

在tensorflow 2中,你不需要turorial包,使用:

tf.keras.datasets.mnist.load_data(
    path='mnist.npz'
)

你可以阅读更多: 这里

In in tensorflow 2, you don't need turorial package, use:

tf.keras.datasets.mnist.load_data(
    path='mnist.npz'
)

You can read more : here

一瞬间的火花 2025-01-25 09:37:55

看来tensorflow现在已经为数据集创建了一个单独的存储库..只需在下面导入:

import tensorflow_datasets as datasets
mnist = datasets.load(name='mnist')

这可能需要安装其他依赖项,如下所示:如果您从计算机运行jupyter。
但在 Colab 上,它会立即导入它,因为分配给您的 colab EC2/docker 实例将预安装这些。

以下是我从 Ananconda 运行 jupyter 后需要安装的依赖项。

  1. pip install tensorflow-datasets
  2. conda install -c conda-forge ipywidgets
  3. pip install ipywidgets
  4. pip install IProgress
  5. jupyter nbextension enable --py widgetsnbextension
  6. pip install ipywidgets widgetsnbextension pandas-profiling
  7. conda install -c conda-forge nodejs=16.6.1

It seems that tensorflow has created a separated repo for datasets now..just import below :

import tensorflow_datasets as datasets
mnist = datasets.load(name='mnist')

This might require bit of installing of other dependencies like below: if you run jupyter from your machine.
But on Colab it will import it in a jiffy since colab EC2/docker instance assigned to you will have these preinstalled.

Below were the dependencies I needed to install since I run jupyter from Ananconda.

  1. pip install tensorflow-datasets
  2. conda install -c conda-forge ipywidgets
  3. pip install ipywidgets
  4. pip install IProgress
  5. jupyter nbextension enable --py widgetsnbextension
  6. pip install ipywidgets widgetsnbextension pandas-profiling
  7. conda install -c conda-forge nodejs=16.6.1
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文