Тимур Мамедов
Ученик
(115),
на голосовании
1 месяц назад
Помогите исправить ошибки в коде
import tensorflow as tf import numpy as np import random import matplotlib.pyplot as plt from tensorflow import keras %matplotlib inline from tensorflow.keras.datasets import fashion_mnist from tensorflow.keras.models import Sequential from tensorflow.keras.layers import Dense, Dropout from tensorflow. keras import utils
import tensorflow as tf
import numpy as np
import random
import matplotlib.pyplot as plt
from tensorflow import keras
%matplotlib inline
from tensorflow.keras.datasets import fashion_mnist
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Dropout
from tensorflow. keras import utils
(x_train, y_train), (x_test, y_test) = fashion_mnist.load_data()
x_train = x_train/255
x_test= x_test/255
model = Sequential([
keras.layers. Flatten (input_shape=(28, 28)),
keras.layers. Dense (128, activation=' relu'),
keras. layers. Dense (10, activation='softmax')
])
model.compile(optimizer=tf.keras.optimizers. SGD (), loss='sparse_categorical_crossentropy', metrics=['accuracy'])
model.fit (x_train, y_train, epochs=100)
test_loss, test_acc = model.evaluate(x_test, y_test) print (f'Accuracy = {test_acc}, Loss = {test_loss}')
313/313 [=============================] 0s 1ms/step loss: 0.4300 accuracy: 0.8855
Accuracy 0.8855000138282776, Loss = 0.4299611449241638
predicts = model.predict(x_test)
313/313 [=======]- 0s 1ms/step
inp = int(input('Номер картинки: '))
print(predicts [inp])
ind_class
np.argmax(predicts [inp])
print(class_names[ind_class])
plt.figure()
plt.imshow(x_test[inp])
plt.colorbar()
plt.grid(False)