{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import numpy as np \nimport tensorflow as tf\nfrom tensorflow import keras\nimport matplotlib.pyplot as plt\n","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-08-15T05:56:41.535568Z","iopub.execute_input":"2023-08-15T05:56:41.535981Z","iopub.status.idle":"2023-08-15T05:56:41.542444Z","shell.execute_reply.started":"2023-08-15T05:56:41.535946Z","shell.execute_reply":"2023-08-15T05:56:41.541364Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Load the Fashion MNIST dataset\nfashion_mnist = keras.datasets.fashion_mnist\n(train_images, train_labels), (test_images, test_labels) = fashion_mnist.load_data()\n\n# Preprocess the data\ntrain_images = train_images / 255.0\ntest_images = test_images / 255.0\n","metadata":{"execution":{"iopub.status.busy":"2023-08-15T05:56:41.544739Z","iopub.execute_input":"2023-08-15T05:56:41.545085Z","iopub.status.idle":"2023-08-15T05:56:42.126326Z","shell.execute_reply.started":"2023-08-15T05:56:41.545058Z","shell.execute_reply":"2023-08-15T05:56:42.124768Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Define the model architecture\nmodel = keras.Sequential([\n    keras.layers.Flatten(input_shape=(28, 28)),\n    keras.layers.Dense(128, activation='relu'),\n    keras.layers.Dense(10, activation='softmax')\n])\n\n# Compile the model\nmodel.compile(optimizer='adam',\n              loss='sparse_categorical_crossentropy',\n              metrics=['accuracy'])\n\n","metadata":{"execution":{"iopub.status.busy":"2023-08-15T05:56:42.128054Z","iopub.execute_input":"2023-08-15T05:56:42.128634Z","iopub.status.idle":"2023-08-15T05:56:42.181222Z","shell.execute_reply.started":"2023-08-15T05:56:42.128603Z","shell.execute_reply":"2023-08-15T05:56:42.180254Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Train the model\nmodel.fit(train_images, train_labels, epochs=20)\n\n# Evaluate the model\ntest_loss, test_acc = model.evaluate(test_images, test_labels)\nprint('Test accuracy:', test_acc)","metadata":{"execution":{"iopub.status.busy":"2023-08-15T05:56:42.183224Z","iopub.execute_input":"2023-08-15T05:56:42.183541Z","iopub.status.idle":"2023-08-15T05:58:39.601746Z","shell.execute_reply.started":"2023-08-15T05:56:42.183513Z","shell.execute_reply":"2023-08-15T05:58:39.600174Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Show  output images\npredictions = model.predict(test_images)\nnum_images = 5\n\nfor i in range(num_images):\n    plt.imshow(test_images[i], cmap='gray')\n    plt.title(f\"True Label: {test_labels[i]}, Predicted Label: {np.argmax(predictions[i])}\")\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2023-08-15T05:58:39.603283Z","iopub.execute_input":"2023-08-15T05:58:39.603605Z","iopub.status.idle":"2023-08-15T05:58:41.115171Z","shell.execute_reply.started":"2023-08-15T05:58:39.603577Z","shell.execute_reply":"2023-08-15T05:58:41.113615Z"},"trusted":true},"execution_count":null,"outputs":[]}]}