<jupyter_start><jupyter_text>Hey Nikhil:I downloaded the folder from Dropbox and unzipped it. Then it create a folder called mcit-hackathon-aug-2020 on GCP.Then I created three folders (data with the cleaned data, keypoints with the keypoints, and train_val for training and validation sets)What I'm doing is create a logic using regex to seperate the file name (e.g 01166A18.jpg) into the index (01166) and the age(18).Then I'll create n+1 classes of ages (from age 0 to age n)And then I'll link the photos to the classes. (This will be tricky)Then create a DataBunchThe rest should be to create ResNet50 learner, then learn.  Data Prep<jupyter_code>!pip install -Uqq fastbook
import fastbook
fastbook.setup_book()
from fastbook import *
from fastai.vision.widgets import *
!pwd
base_dir = "/home/jupyter/mcit-hackathon-aug-2020/"
base_path = Path(base_dir)

data_dir = base_dir + "data/"
data_path = Path(data_dir)
data_path.ls()<jupyter_output><empty_output><jupyter_text>https://github.com/JingchunCheng/All-Age-Faces-Dataset  DataBlock creation<jupyter_code>fnames = get_image_files(data_path)
dblock = DataBlock()
def label_func(fname):
    return int(fname.name[-6:-4])
dblock = DataBlock( blocks = (ImageBlock, RegressionBlock), 
                    get_items = get_image_files,
                    get_y     = label_func,
                    splitter  = RandomSplitter(),
                    item_tfms = Resize(224))
dsets = dblock.datasets(data_path)
dsets.train[0]
len(dsets.train),len(dsets.valid)
dls = dblock.dataloaders(data_path)
dls.valid.show_batch(max_n=4, nrows=1)<jupyter_output><empty_output><jupyter_text>Train Model (stage 1)<jupyter_code>learn = cnn_learner(dls, resnet50, metrics=rmse)
learn.model
learn.fit_one_cycle(4)<jupyter_output><empty_output><jupyter_text>Loss is still pretty big.More training to go.<jupyter_code>learn.fit_one_cycle(4)<jupyter_output><empty_output><jupyter_text>Since training loss is lower than valid_loss, if we keep training, we would run into overfitting. Let's save the model, unfreeze, find the learning rate and fine tune it.<jupyter_code># Save the weights of the network for future reuse
learn.save('stage-1')
learn.unfreeze()
# Unfreeze the layers to test
learn.lr_find()
# Find the learning rate<jupyter_output><empty_output><jupyter_text>Data Cleaning<jupyter_code>fns = get_image_files('data')
w = ImagesCleaner(('A','B'))
w.set_fns(fns)
w<jupyter_output><empty_output><jupyter_text>Training the model (stage 2) with fine tuning<jupyter_code>learn_2 = cnn_learner(dls, resnet50, metrics=rmse)
learn_2.load('stage-1');<jupyter_output><empty_output><jupyter_text>Using the learning rate plot, we found that the steepest learning rate was 2.2908675418875646e-06. So let's picked 2e-6 as the rate.<jupyter_code>learn_2.fine_tune(4, lr=2e-6)<jupyter_output><empty_output><jupyter_text>Looks like we could eek out more from this. Going on the right path!Before tuning more, let's save the stage along the way to err on the safe side.<jupyter_code>learn_2.save('stage-2')
learn_2.fine_tune(4, lr=2e-6)
learn_2.unfreeze()
learn_2.lr_find()<jupyter_output><empty_output><jupyter_text>We could see that after stage 2, things didn't get any better as it bottoms out at 7 for rmse. Let's call it a day and export this model out<jupyter_code>learn_2.save('stage-3')<jupyter_output><empty_output><jupyter_text>Exporting stage 3<jupyter_code>learn_2.export()<jupyter_output><empty_output>