<jupyter_start><jupyter_text>1.  Попробуйте обучить нейронную сеть на Keras на Fashion-MNIST датасете. Опишите в комментарии к уроку - какой результата вы добились от нейросети? Что помогло вам улучшить ее точность?2. Поработайте с документацией Keras.<jupyter_code>import numpy as np
from keras.datasets import mnist

(train_images, train_labels), (test_images, test_labels) = mnist.load_data()
from tensorflow.python.client import device_lib

def get_available_gpus():
    local_device_protos = device_lib.list_local_devices()
    return [x.name for x in local_device_protos if x.device_type == 'GPU']
# Normalize the images.
train_images = (train_images / 255) - 0.5
test_images = (test_images / 255) - 0.5

# Flatten the images.
train_images = train_images.reshape((-1, 784))
test_images = test_images.reshape((-1, 784))

print(train_images.shape) # (60000, 784)
print(test_images.shape)  # (10000, 784)
from keras.models import Sequential
from keras.layers import Dense, Dropout
from keras.utils import to_categorical
# Build the model.
model = Sequential([
  Dense(512, activation='relu', input_shape=(784,)),
  Dropout(0.25),  
  Dense(512, activation='sigmoid'),
  Dropout(0.25),
  Dense(256, activation='relu'),
  Dropout(0.25),    
  Dense(10, activation='softmax'),
])
# Compile the model.
model.compile(
  optimizer='adam',
  loss='categorical_crossentropy',
  metrics=['accuracy'],
)
# Train the model.
model.fit(
  train_images,
  to_categorical(train_labels),
  epochs=25,
  batch_size=256,
)
# Evaluate the model.
model.evaluate(
  test_images,
  to_categorical(test_labels)
)


# Save the model to disk.
model.save_weights('model.h5')


# Load the model from disk later using:
# model.load_weights('model.h5')


# Predict on the first 5 test images.
predictions = model.predict(test_images[:10])

# Print our model's predictions.
print(np.argmax(predictions, axis=1)) # [7, 2, 1, 0, 4]

# Check our predictions against the ground truths.
print(test_labels[:10]) # [7, 2, 1, 0, 4]<jupyter_output>[7 2 1 0 4 1 4 9 5 9]
[7 2 1 0 4 1 4 9 5 9]
{'fraction_non_alphanumeric': 0.12068126520681265, 'fraction_numerical': 0.049635036496350364, 'mean_word_length': 4.92507204610951, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '558032', 'license': 'Apache-2.0', 'n_tokens_mistral': 843, 'n_tokens_neox': 784, 'n_words': 203, 'path': 'Homework_02.ipynb', 'repo_name': 'Alibek80/Neural-Networks-Basics', 'size': '2055'}