Lesson 3
Last updated
Last updated
Pytorch has this class dataset
It does nothing yet.
It defines 2 things: __getitem__ (=your object and be indexed with [0]), and __len__ (you can do len(object) = gives the len).
The starting point for our data is: getitem, and how big is the dataset. It's not enough on its own to train a model. We need to be able to get minibatches. This is done using a dataloader.
It takes a dataset and its constructor (it can get items now) it's going to get items at random and create a minibatch for whatever size you ask for and pop it on the gpu and put it into our model.
These 2 aren't enough to create a model yet, we need a validation set as well. In fast ai we use a DataBunch for this: it binds together a train_dl (train dataloader) and a valid_dl.
Now this is an object that you can send this off to a learner and start fitting.
By defaut they will flip randomly each image, but only horizontally. For dog and cat dataset it makes sense but for satellite imagery you'd want to flip.
Wrap: If you look from above or below, the object changes shape so you'd want to include this. But for satellite images you wouldn't need this.
Pretty much the same thing as before except for passing multiple labels at the beginning,etc.
Something else that's different are the metrics - Here we're getting accuracy and fbeta. (this is because kaggle's evaluation - fscore (f2 for this dataset)
We need to change the threshold.
data.c : gives you the number of classes you have. For this dataset we have 17.
Question: in production what can you do with misclassified images? Can you use them to improve the model?
Yes - it's up to you to get the feedback from the user and know it's wrong. Then you can log it.
Then create a dataset with all the misclassified instances - which are particularily interesting so we can fit at a higher learning rate. You pass in the correct classifications.
INitially we created a model with image size = 128. Why? We wanted to experiment quickly. Also, we now have a model that's pretty good at recognizing images of 128*128.
If we want one that's good at 256, then we can start with the model that was trained on 128*128 and use that = transfer learning.
You loose the overfitting because we're learning on a new data set. We'll use the same learning but use a new learner that's 256*256.
You use the same learner so we start with a pretrained model. Then we replace our databunch with the new one - learn.data = data
Freeze again - new lr_find(), get lr's, fit()
Then usual steps - unfreeze, fit, etc.
Classification problem for every single pixel, and for every single image. You need a datasert where someone already labeled the dataset like this:
Common in self driving cars, or radiographic, the metal lesion / weakness dataset on kaggle.
For segmentation we don't just use an convolutional NN. We also use something called U-net. To create a segmentation model we should use a unet - Fastai library has it. learner.create_unet(...)
Makes the learning rate start low, goes up and down again. Why is that a good idea? Getting the right learning rate is important because it zooms to the best spot very quickly, instead of taking a lot of time or diverging.
As we get closer to the final spot, we really want our lr to decrease because we're getting close to the right spot. What happens is uusually have a loss function surface like this:
We want an lr that is high enough to go over the bumps, but when we're close to the right answer we take smaller and smaller steps.
This is how the lr varies with fit one cycle. The idea of decreasing the lr at the end is not new, it's call aneiling (sp?). But increasing it at the start is new.
Actually the loss surface looks more like this:
Kinda flat where the best solution is. So if you find a solution in one of the whole, it's not great. With a small lr you can't really reach the flat part.
It helps the model explore all the loss surface. It also means we can train our model more quickly.
Here with plot_losses the training and validation error goes slightly up, then back down. When that happens you know you've found a really good lr. If you don't have this graph you can try increasing the lr very slightly.
Momentum and fit one cycle
Momentum levels are on the right graph.