본문 바로가기

인공지능(AI)/Udacity tensorflow 강의

[Lesson 2] Your First Model: Fashion MNIST (2)

- When training a Machine Learning model, I always need to split my data set into at least two different partitions, the data I use for training, and the data I use for testing.

 

- We want to test it on data that it hasn't seen before, to see how well it performs.

 

- If we did not do this, we wouldn't know if the neural network has decided to memorize the images it saw during trainig.

 

- TensorFlow Datasets provides a collection of datasets ready to use with TensorFlow.

 

Introducing TensorFlow Datasets

Public datasets fuel the machine learning research rocket (h/t Andrew Ng), but it’s still too difficult to simply get those datasets into…

medium.com

- Datasets are typically split into different subsets to be used at various stages of training and evaluation of the neural network.

 

  • Training Set: The data used for training the neural network.
  • Test set: The data used for testing the final performance of our neural network.

- It is common to use Validation dataset, which is not used for training. Instead, it it used to test the model during training. This is done after some set number of training steps, and gives us an indication of how the training is progressing.

 

- The validation set is used again when training is complete to measure the final accuracy of the model.

 

- You can read more about all this in the Training and Test Sets lesson of Google’s Machine Learning Crash Course.

 

학습 및 테스트 세트  |  머신러닝 단기집중과정  |  Google Developers

테스트 세트는 학습 세트로부터 개발한 모델을 평가하는 데 사용되는 데이터 세트입니다. 예상 시간: 2분 학습 목표 데이터 세트를 학습 세트와 테스트 세트로 구분하는 데 따르는 장점을 알아��

developers.google.com

 

<Colab Notebook>

- To access the Colab Notebook, login to your Google account and click on the link below:

Fashion MNIST

 

Google Colaboratory

 

colab.research.google.com

- Loading it using TensorFlow Datasets is easy. It will also split it into a train dataset and a test dataset for you.

ex) dataset, metadata = tfds.load('fashion_mnist', as_supervised=True, with_info=True)

train_dataset, test_dataset = dataset['train'], dataset['test']

 

- We create a list to map the numeric value to a human readable string.

ex) class_names = ['T-shirt/top''Trouser''Pullover''Dress''Coat', 'Sandal', 'Shirt', 'Sneaker', 'Bag', 'Ankle boot']

 

- The value of each pixel in the image data is an integer in the range [0,255]. For the model to work properly, these values need to be normalized to the range [0,1]. -> Create a normalization function, and then apply it to each image in the test and train datasets. (Preprocessing)

 

- The basic building block of a neural network is the layer. This network has three layers:

 

  • input tf.keras.layers.Flatten : This layer transforms the images from a 2d-array of 28 × 28 pixels, to a 1d-array of 784 pixels (28*28). 
  • "hidden" tf.keras.layers.Dense : A densely connected layer of 128 neurons. Each neuron (or node) takes input from all 784 nodes in the previous layer.
  • output tf.keras.layers.Dense : A 128-neuron, followed by 10-node softmax layer. Each node represents a class of clothing.

- These are added during the model's compile step:

 

  • Loss function : An algorithm for measuring how far the model's outputs are from the desired output. The goal of training is this measures loss.
  • Optimizer : An algorithm for adjusting the inner parameters of the model in order to minimize loss.
  • Metrics : Used to monitor the training and testing steps. The following example uses accuracy, the fraction of the images that are correctly classified.

- Training is performed by calling the model.fit method.

ex) model.fit(train_dataset, epochs=5, steps_per_epoch=math.ceil(num_train_examples/BATCH_SIZE))

 

- We can use the argmax function on Numpy to print the largest index.

ex) np.argmax(predictions[0])

< Celsius vs MNIST >

  • Celsius to Farenheit is a regression problem.
  • fasion MNIST is a classification problem

Different between two types of problems

- All of our machine learning models is one of these categories.

  • Regression: A model that outputs a single value. For example, an estimate of a house’s value.
  • Classification: A model that outputs a probability distribution across several categories. For example, in Fashion MNIST, the output was 10 probabilities, one for each of the different types of clothing. Remember, we use Softmax as the activation function in our last Dense layer to create this probability distribution.

- The softmax activation function calculated the probability distribution.

 

- Covers regression vs classification :  video

-  It also describes another regression model that predicts the fuel efficiency for different types of cars.