Coder Social home page Coder Social logo

arminbaz / utk-face Goto Github PK

View Code? Open in Web Editor NEW
19.0 4.0 4.0 100.34 MB

PyTorch Implementation of a Multi-Output Neural Network on the UTK Face Dataset to predict a person's age (range), ethnicity, and gender.

Jupyter Notebook 81.92% Python 18.08%
utk-face multi-output multi-output-networks cnn pytorch utkface utkface-dataset

utk-face's Introduction

UTK-Face Project

This is a project based on the UTK Face dataset, luckily someone was nice enough to clean up the dataset and make it publicly available here: https://www.kaggle.com/nipunarora8/age-gender-and-ethnicity-face-data-csv

This repo contains a multi-output CNN that is capable of predicting the age, gender, and ethnicity of a person from a photo.

Dependencies

  • python - 3.7.4
  • pandas - 1.0.5
  • pytorch - 1.4.0
  • torchvision - 0.5.0
  • tensorboard - 2.4.1
  • tqdm - 4.47.0

Usage

To run the script navigate to /src and run main.py with the following command

    python main.py --num_epochs=e --learning_rate=lr --pre-trained=pt

The argument usage should be self explanatory, further information can be found in the main.py file.

Data

The data is stored in a gzip format to make it easier to download and work with

Src

Within this folder you will find two custom modules

  1. The first custom module is for a custom PyTorch Dataset class to work with the UTK dataset
  2. The second custom module is where I define my trident neural network

Trident Neural Network

The trident neural network is named such because it takes the shape of an upside down trident. We are trying to predict three different things with each image age, gender, and ethnicity.

The steps for the TNN are as follows:

  1. I run the image through the high-level feature extraction layers that closely mimic the architecture of the VGG network.
  2. The high-level features are sent through three seperate branches (hence the trident).
  3. Within each branch low-level features are extracted followed by fully connected layers for classification.

As you can assume the three different branches are for the three predictions.

Test Results

I got these test results after training the network so that the training accuracy for each task hit 90%. You can see how I did that in the horribly unorganized colab notebook in /colab/TrainTridentMain.ipynb.

Task Accuracy
Age 45.86%
Gender 89.01%
Ethnicity 76.46%

As you can see the accuracy is not that great, especially for the age prediction task. My hypothesis is that predicting age is actually a very difficult task because there is not only variation between how people age from person to person, but different genders and ethnicities show age at different rates too. Therefore, we have both inter and intra variance when it comes to age.

I might revisit this problem in the future by first trying to feedback the gender and ethnicity predictions as one hot vectors into the age prediction branch of the neural network. Or, it might be as simple as using a more powerful method that involves using a better network (ResNet/DenseNet) and/or the use of transfer learning.

utk-face's People

Contributors

arminbaz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

utk-face's Issues

age model fo utk face datase

thanks about your work it is good work
i think in age model the accuracy is too low especially in age group i think you can ameliorate it by add attention in images processing

AttributeError: 'DataFrame' object has no attribute 'bins'

Hi, when I try Sandbox.ipynb, it occurs error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[5], line 27
     21 test_transform = transforms.Compose([
     22     transforms.ToTensor(),
     23     transforms.Normalize((0.49,), (0.23,))
     24 ])
     26 # Construct the custom pytorch datasets
---> 27 train_set = UTKDataset(train_dataFrame, transform=train_transform)
     28 test_set = UTKDataset(test_dataFrame, transform=test_transform)
     30 # Load the datasets into dataloaders

File [~/](https://vscode-remote+ssh-002dremote-002b7b22686f73744e616d65223a224c5346227d.vscode-resource.vscode-cdn.net/home/lsf/%E6%A1%8C%E9%9D%A2/UTK-Face/~/)desktop[/UTK-Face/src/CustomUTK.py:29](https://vscode-remote+ssh-002dremote-002b7b22686f73744e616d65223a224c5346227d.vscode-resource.vscode-cdn.net/UTK-Face/src/CustomUTK.py:29), in UTKDataset.__init__(self, dataFrame, transform)
     26 self.data = arr
     28 # get the age, gender, and ethnicity label arrays
---> 29 self.age_label = np.array(dataFrame.bins[:])         # Note : Changed dataFrame.age to dataFrame.bins
     30 self.gender_label = np.array(dataFrame.gender[:])
     31 self.eth_label = np.array(dataFrame.ethnicity[:])

File [~/anaconda3/envs/utk-face/lib/python3.8/site-packages/pandas/core/generic.py:5902](https://vscode-remote+ssh-002dremote-002b7b22686f73744e616d65223a224c5346227d.vscode-resource.vscode-cdn.net/home/lsf/%E6%A1%8C%E9%9D%A2/UTK-Face/~/anaconda3/envs/utk-face/lib/python3.8/site-packages/pandas/core/generic.py:5902), in NDFrame.__getattr__(self, name)
   5895 if (
   5896     name not in self._internal_names_set
   5897     and name not in self._metadata
   5898     and name not in self._accessors
   5899     and self._info_axis._can_hold_identifiers_and_holds_name(name)
...
   5900 ):
   5901     return self[name]
-> 5902 return object.__getattribute__(self, name)

AttributeError: 'DataFrame' object has no attribute 'bins'

This is because when I run the command:

# Construct the custom pytorch datasets
train_set = UTKDataset(train_dataFrame, transform=train_transform)

Can you help fix the bug?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.