Loading

Age Prediction

Age Prediction Using pretrained CNN

Finetuning a model from https://github.com/timesler/facenet-pytorch, pretrained on VGGFace2

Zac

Image Classification Using pretrained CNN

Finetuning a model from https://github.com/timesler/facenet-pytorch, pretrained on VGGFace2

Download the files 💾

In [ ]:
from google.colab import drive
drive.mount('/content/drive')
Mounted at /content/drive
In [ ]:
!pip install aicrowd-cli
%load_ext aicrowd.magic
In [29]:
%aicrowd login
Please login here: https://api.aicrowd.com/auth/J9a2-03Rc_E8XCxLqdIo7dq54xMSbUnWt2KhPJW9CNQ
API Key valid
Gitlab access token valid
Saved details successfully!
In [ ]:
!rm -rf data
!mkdir data
%aicrowd ds dl -c age-prediction -o data
In [ ]:
!unzip -qq data/train.zip -d data/train
!unzip -qq data/val.zip -d data/val
!unzip -qq data/test.zip -d data/test

Importing Libraries:

In [ ]:
!pip install facenet_pytorch
In [ ]:
import pandas as pd
import numpy as np
import torch
import csv
import os
import cv2
import glob
import torch
from torch import nn
import numpy as np
from matplotlib import pyplot as plt
from tqdm import tqdm
import albumentations as albu
from facenet_pytorch import InceptionResnetV1, MTCNN

Visualising data:

In [ ]:
def open_img(name):
    img = cv2.imread(name)
    img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
    return img

def show(img):
    plt.xticks([]), plt.yticks([])
    plt.imshow(img)


def show_all(images, cols=3):
    num_rows = (len(images) - 1) // cols + 1
    plt.rcParams['figure.figsize'] = [20, 7 * num_rows]
    for i, im in enumerate(images):
        plt.subplot(num_rows, cols, i+1)
        show(im)
    plt.show()
    plt.rcParams['figure.figsize'] = [20, 10]


device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
In [16]:
names = ["0000v", "00boq", "01bn8", "03p0f", "04gd1", "04tx0"]
# names = ["dloyr", "e6yjc", "k675i", "ni3p4", "ro01p", "svx4s"]
imgs = [open_img("data/val/"+name+".jpg") for name in names]

show_all(imgs)