Skip to content

Latest commit

 

History

History
167 lines (108 loc) · 4.92 KB

File metadata and controls

167 lines (108 loc) · 4.92 KB

Homework

Note: sometimes your answer doesn't match one of the options exactly. That's fine. Select the option that's closest to your solution.

Dataset

In this homework, we'll build a model for predicting if we have an image of a bee or a wasp. For this, we will use the "Bee or Wasp?" dataset that was obtained from Kaggle and slightly rebuilt.

You can download the dataset for this homework from here:

wget https://github.com/SVizor42/ML_Zoomcamp/releases/download/bee-wasp-data/data.zip
unzip data.zip

In the lectures we saw how to use a pre-trained neural network. In the homework, we'll train a much smaller model from scratch.

Note: you will need an environment with a GPU for this homework. We recommend to use Saturn Cloud. You can also use a computer without a GPU (e.g. your laptop), but it will be slower.

Data Preparation

The dataset contains around 2500 images of bees and around 2100 images of wasps.

The dataset contains separate folders for training and test sets.

Model

For this homework we will use Convolutional Neural Network (CNN). Like in the lectures, we'll use Keras.

You need to develop the model with following structure:

  • The shape for input should be (150, 150, 3)
  • Next, create a convolutional layer (Conv2D):
    • Use 32 filters
    • Kernel size should be (3, 3) (that's the size of the filter)
    • Use 'relu' as activation
  • Reduce the size of the feature map with max pooling (MaxPooling2D)
    • Set the pooling size to (2, 2)
  • Turn the multi-dimensional result into vectors using a Flatten layer
  • Next, add a Dense layer with 64 neurons and 'relu' activation
  • Finally, create the Dense layer with 1 neuron - this will be the output
    • The output layer should have an activation - use the appropriate activation for the binary classification case

As optimizer use SGD with the following parameters:

  • SGD(lr=0.002, momentum=0.8)

For clarification about kernel size and max pooling, check Office Hours.

Question 1

Since we have a binary classification problem, what is the best loss function for us?

  • mean squared error
  • binary crossentropy
  • categorical crossentropy
  • cosine similarity

Note: since we specify an activation for the output layer, we don't need to set from_logits=True

Question 2

What's the number of parameters in the convolutional layer of our model? You can use the summary method for that.

  • 1
  • 65
  • 896
  • 11214912

Generators and Training

For the next two questions, use the following data generator for both train and test sets:

ImageDataGenerator(rescale=1./255)
  • We don't need to do any additional pre-processing for the images.
  • When reading the data from train/test directories, check the class_mode parameter. Which value should it be for a binary classification problem?
  • Use batch_size=20
  • Use shuffle=True for both training and test sets.

For training use .fit() with the following params:

model.fit(
    train_generator,
    epochs=10,
    validation_data=test_generator
)

Question 3

What is the median of training accuracy for all the epochs for this model?

  • 0.20
  • 0.40
  • 0.60
  • 0.80

Question 4

What is the standard deviation of training loss for all the epochs for this model?

  • 0.031
  • 0.061
  • 0.091
  • 0.131

Data Augmentation

For the next two questions, we'll generate more data using data augmentations.

Add the following augmentations to your training data generator:

  • rotation_range=50,
  • width_shift_range=0.1,
  • height_shift_range=0.1,
  • zoom_range=0.1,
  • horizontal_flip=True,
  • fill_mode='nearest'

Question 5

Let's train our model for 10 more epochs using the same code as previously.

Note: make sure you don't re-create the model - we want to continue training the model we already started training.

What is the mean of test loss for all the epochs for the model trained with augmentations?

  • 0.18
  • 0.48
  • 0.78
  • 0.108

Question 6

What's the average of test accuracy for the last 5 epochs (from 6 to 10) for the model trained with augmentations?

  • 0.38
  • 0.58
  • 0.78
  • 0.98

Submit the results

  • Submit your results here: https://forms.gle/5sjtM3kzY9TmLmU17
  • If your answer doesn't match options exactly, select the closest one
  • You can submit your solution multiple times. In this case, only the last submission will be used

Deadline

The deadline for submitting is November 20 (Monday), 23:00 CET. After that the form will be closed.