MNIST (модифицированная база данных Национального института стандартов и технологий). В области компьютерного зрения и глубокого обучения MNIST является очень известным набором данных. Он содержит коллекцию из 70 000 x28x28 изображений рукописных цифр от 0 до 9. Она разделена на обучающую и тестовую выборки.

we will first have to import the MNIST datasets from keras module.
We will use following line of code:
from tensorflow.keras.datasets import mnist

(train_images, train_labels), (test_images, test_labels) = mnist.load_data()
print(len(train_images))
print(len(train_labels))
print(len(test_images))
print(len(test_labels))
print(test_images.shape)
train_images.shape
import matplotlib.pyplot as plt

index = 10

digit = train_images[index]
print("Class Label:",train_labels[index])
#digit.shape

plt.imshow(digit, cmap=plt.cm.binary)
plt.show()

digit = test_images[0]
print("Class Label:",test_labels[0])
#digit.shape

plt.imshow(digit, cmap=plt.cm.binary)
plt.show()

import numpy as np
print(train_labels)
print(len(train_labels))
print(np.unique(train_labels))
output
[5 0 4 ... 5 6 8]
60000
[0 1 2 3 4 5 6 7 8 9]
import numpy as np
print(test_labels)
print(len(test_labels))
print(np.unique(test_labels))


output
[7 2 1 ... 4 5 6]
10000
[0 1 2 3 4 5 6 7 8 9]
a = np.array([1,2,3,7])
print(a.ndim)
a.shape


output
1
(4,)
b = np.random.randint(0,255 ,size=(28,28))
print(b.shape)
b1 = b.ravel()
print(b1.shape)

# input_shape=(28*28, )
# input_shape=(784,)

output
(28, 28)
(784,)

Архитектура сети

Выбор правильного слоя для вашей модели