0

I tried to import some examples from mnist in tensorflow version 2. But the examples are all about tensorflow version 1 and I modifed my tensorflow using

import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()

here, I tried to use

from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets("MNIST_data/", one_hot=True)

but ModuleNotFoundError: No module named 'tensorflow.examples' appeared in my VSCode terminal, so I tried with

from keras import Sequential
from tensorflow import keras
import os
mnist = tf.keras.datasets.mnist
(x_train, y_train), (x_test, y_test) = mnist.load_data()

In this way, data loading was successful but the example code,

batch_xs, batch_ys = mnist.next_batch(100)

did not work.

To get the tutorial folder in my tensorflow, I also tried to download from github, but there was no tutorial folder according to ModuleNotFoundError: No module named 'tensorflow.examples'

However, there was no folder named tensorflow_core in my C:\Users\User\anaconda3\envs\tensorflow\Lib\site-packages

help me

Max S.
  • 3,704
  • 2
  • 13
  • 34
  • Just use [an up-to-date tutorial](https://www.tensorflow.org/tutorials), there is no reason to be using TF1 for MNIST. – xdurch0 Jan 26 '23 at 08:57

1 Answers1

0

tensorflow.example is no longer in use and most of the these datasets are available in TF datasets library which can be accessible by using tensorflow.keras.datasets api.

You can refer to this tutorial for the same example code where you just need to replace the fashion_mnist dataset with mnist to access mnist dataset.

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

It is recommended to use Tensorflow 2.x with the latest version. So please update the tensorflow version to 2.x.

pip install --upgrade tensorflow  # to install upgraded tensorflow version

To access few example code:

train_labels = train_labels[:1000]
test_labels = test_labels[:1000]