{ "cells": [ { "cell_type": "markdown", "metadata": { "id": "jYysdyb-CaWM" }, "source": [ "# Basic classification: Classify images of clothing" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Load model\n", "\n", "The following code has nothing to do with machine learning and can be skipped." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import os\n", "import requests" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "classification_model_url = \"https://static-1300131294.cos.ap-shanghai.myqcloud.com/data/deep-learning/overview/classification.h5\"\n", "\n", "notebook_path = os.getcwd()\n", "\n", "tmp_folder_path = os.path.join(notebook_path, \"tmp\")\n", "\n", "if not os.path.exists(tmp_folder_path):\n", " os.makedirs(tmp_folder_path)\n", "\n", "file_path = os.path.join(tmp_folder_path,\"overview\")\n", "\n", "if not os.path.exists(file_path):\n", " os.makedirs(file_path)\n", "\n", "zip_store_path = os.path.join(file_path, \"zip-store\")\n", "\n", "if not os.path.exists(zip_store_path):\n", " os.makedirs(zip_store_path)\n", "\n", "classification_model_response = requests.get(classification_model_url)\n", "\n", "classification_model_name = os.path.basename(classification_model_url)\n", "\n", "classification_model_save_path = os.path.join(file_path, classification_model_name)\n", "\n", "with open(classification_model_save_path, \"wb\") as file:\n", " file.write(classification_model_response.content)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Overview: Deep learning, machine learning, and AI" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "\n", "Consider the following definitions to understand deep learning vs. machine learning vs. AI:\n", "\n", "- Deep learning is a subset of machine learning that's based on artificial neural networks. The learning process is deep because the structure of artificial neural networks consists of multiple input, output, and hidden layers. Each layer contains units that transform the input data into information that the next layer can use for a certain predictive task. Thanks to this structure, a machine can learn through its own data processing.\n", "- Machine learning is a subset of artificial intelligence that uses techniques (such as deep learning) that enable machines to use experience to improve at tasks. The learning process is based on the following steps:\n", "\n", "1. Feed data into an algorithm. (In this step you can provide additional information to the model, for example, by performing feature extraction.)\n", "Use this data to train a model.\n", "2. Test and deploy the model.\n", "3. Consume the deployed model to do an automated predictive task. (In other words, call and use the deployed model to receive the predictions returned by the model.)\n", "4. Artificial intelligence (AI) is a technique that enables computers to mimic human intelligence. It includes machine learning.\n", "\n", "Generative AI is a subset of artificial intelligence that uses techniques (such as deep learning) to generate new content. For example, you can use generative AI to create images, text, or audio. These models leverage massive pre-trained knowledge to generate this content.\n", "\n", "By using machine learning and deep learning techniques, you can build computer systems and applications that do tasks that are commonly associated with human intelligence. These tasks include image recognition, speech recognition, and language translation." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Overview of this guide" ] }, { "cell_type": "markdown", "metadata": { "id": "FbVhjPpzn6BM" }, "source": [ "This guide provide a simple sample of deep learning. It will help you understand the model framework for deep learning.\n", "\n", "This guide trains a neural network model to classify images of clothing, like sneakers and shirts. It's okay if you don't understand all the details; this is a fast-paced overview of a complete TensorFlow program with the details explained as you go.\n", "\n", "This guide uses [tf.keras](https://www.tensorflow.org/guide/keras), a high-level API to build and train models in TensorFlow." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2023-07-27T05:33:07.600803Z", "iopub.status.busy": "2023-07-27T05:33:07.600378Z", "iopub.status.idle": "2023-07-27T05:33:10.127672Z", "shell.execute_reply": "2023-07-27T05:33:10.126938Z" }, "id": "dzLKpmZICaWN" }, "outputs": [], "source": [ "# TensorFlow and tf.keras\n", "import tensorflow as tf\n", "\n", "# Helper libraries\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "\n", "print(tf.__version__)" ] }, { "cell_type": "markdown", "metadata": { "id": "yR0EdgrLCaWR" }, "source": [ "## Import the Fashion MNIST dataset" ] }, { "cell_type": "markdown", "metadata": { "id": "DLdCchMdCaWQ" }, "source": [ "This guide uses the [Fashion MNIST](https://github.com/zalandoresearch/fashion-mnist) dataset which contains 70,000 grayscale images in 10 categories. The images show individual articles of clothing at low resolution (28 by 28 pixels), as seen here:\n", "\n", "
| \n",
" |
| \n",
" Figure 1. Fashion-MNIST samples (by Zalando, MIT License). \n", " |
| Label | \n", "Class | \n", "
|---|---|
| 0 | \n", "T-shirt/top | \n", "
| 1 | \n", "Trouser | \n", "
| 2 | \n", "Pullover | \n", "
| 3 | \n", "Dress | \n", "
| 4 | \n", "Coat | \n", "
| 5 | \n", "Sandal | \n", "
| 6 | \n", "Shirt | \n", "
| 7 | \n", "Sneaker | \n", "
| 8 | \n", "Bag | \n", "
| 9 | \n", "Ankle boot | \n", "