<jupyter_start><jupyter_text>https://www.tensorflow.org/tutorials/keras/classification?hl=pt-brhttps://www.digitalocean.com/community/tutorials/como-construir-um-classificador-de-machine-learning-em-python-com-scikit-learn-pthttps://machinelearningmastery.com/how-to-load-and-manipulate-images-for-deep-learning-in-python-with-pil-pillow/<jupyter_code>#keras esta dentro do tensorflow
import tensorflow
from tensorflow import keras
import numpy as np
import matplotlib.pyplot as plt
from tensorflow.keras.models import load_model

dataset = keras.datasets.fashion_mnist
((imagens_treino, identificacoes_treino), (imagens_teste, identificacoes_teste)) = dataset.load_data()

imagens_treino_normalizado = imagens_treino/float(255)
imagens_teste_normalizado = imagens_teste/float(255)

print(len(imagens_treino_normalizado))
print(len(imagens_teste_normalizado))
print(imagens_treino.shape)
plt.imshow(imagens_treino[3])
plt.title(identificacoes_treino[3])
plt.colorbar()
plt.imshow(imagens_treino_normalizado[3])
plt.title(identificacoes_treino[3])
plt.colorbar()
modelo = keras.Sequential([
                           keras.layers.Flatten(input_shape=(28, 28)),
                           keras.layers.Dense(256, activation=tensorflow.nn.relu),
                           keras.layers.Dropout(0.2),
                           keras.layers.Dense(10, activation=tensorflow.nn.softmax)
                           ])

modelo.compile(optimizer='adam', 
               loss='sparse_categorical_crossentropy', metrics=['accuracy'])

historico = modelo.fit(imagens_treino_normalizado, identificacoes_treino, epochs=10, validation_split=0.2)
fig, axs = plt.subplots(1,2, figsize=(10,4))

#visualizar a acuracia conforme o treino
axs[0].plot(historico.history['accuracy'])
axs[0].plot(historico.history['val_accuracy'])
axs[0].set_title('acuracia por epoca')
axs[0].set_xlabel('epocas')
axs[0].set_ylabel('acuracia')
axs[0].legend(['treino', 'avaliacao'])

#visualizar a perca conforme o treino
axs[1].plot(historico.history['loss'])
axs[1].plot(historico.history['val_loss'])
axs[1].set_title('perca por epoca')
axs[1].set_xlabel('epocas')
axs[1].set_ylabel('perca')
axs[1].legend(['treino', 'validacao'])
modelo.save('modelo.h5')
modelo_carregado = load_model('modelo.h5', compile=False)
testes = modelo_carregado.predict(imagens_teste_normalizado)

print("teste: ", np.argmax(testes[0]))
print("real: ", identificacoes_teste[0])<jupyter_output>teste:  9
real:  9<jupyter_text>testes de quantidade de itens<jupyter_code>modelo = keras.Sequential([
                           keras.layers.Flatten(input_shape=(28, 28)),
                           keras.layers.Dense(256, activation=tensorflow.nn.relu),
                           keras.layers.Dropout(0.2),
                           keras.layers.Dense(10, activation=tensorflow.nn.softmax)
                           ])

modelo.compile(optimizer='adam', 
               loss='sparse_categorical_crossentropy', metrics=['accuracy'])

historico = modelo.fit(imagens_treino_normalizado[:60000], identificacoes_treino[:60000])<jupyter_output>1875/1875 [==============================] - 5s 3ms/step - loss: 0.5067 - accuracy: 0.8189
{'fraction_non_alphanumeric': 0.14420952982013252, 'fraction_numerical': 0.028084569264752286, 'mean_word_length': 4.409556313993174, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 3, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '266335', 'license': 'MIT', 'n_tokens_mistral': 1192, 'n_tokens_neox': 1133, 'n_words': 131, 'path': 'tensoflow_classificacao_resumida.ipynb', 'repo_name': 'EduardoMoraesRitter/introducao_Deep_Learning_keras_tensorflow', 'size': '3169'}