Project - How to Build a Neural Network for Image Classification with TensorFlow

4 / 8

Splitting the Data

Though the dataset is already split for you between a training set and a test set, it can be useful to split the training set further to have a validation set. We shall do that here.

Let's split the full training set into a validation set and a (smaller) training set. We will also scale the pixel intensities down to the 0-1 range and convert them to floats, by dividing by 255.

INSTRUCTIONS
  • Slice the first 5000 samples from the X_train_full and divide the values by 255. to scale the image pixel values to be in the range 0-1. Store these first 5000 scaled samples in X_valid.

    X_valid = << your code comes here >>[:5000] / 255.
    
  • Store the first 5000 values from y_train_full to form the y_valid.

    y_valid = << your code comes here >>[:5000]
    
  • Similarly, slice the remaining samples from 5000 of the X_train_full and divide the values by 255. to scale the image pixel values to be in the range 0-1. Store these scaled samples in X_train.

    X_train = << your code comes here >>[5000:] / 255.
    
  • Store the remaining samples from 5000 of the y_train_full to form the y_train.

    y_train = << your code comes here >>[5000:]
    
  • Let us print the shapes of the train data, validation data and test data.

    print("Train data shape:",X_train.shape)
    print("Validation data shape:",<< your code comes here >>)
    print("Test data shape:",<< your code comes here >>)
    

    Thus, the train set contains 55000 images, the validation set contains 5,000 images, and the test set contains 10,000 images.

  • Scale the values of the X_test.

    X_test = X_test / 255.
    
Get Hint See Answer


Note - Having trouble with the assessment engine? Follow the steps listed here

Loading comments...