[PYTHON] How to use TokyoTechFes2015


I will explain how to use TokyoTechFes2015. I hope it will be helpful for you to practice the demo and improve the script.


What the script does

Face image category discrimination is performed by machine learning. By learning by changing the dataset folder and below, any face image category can be determined.


First, clone from git.

git clone https://github.com/Arudori5001/TokyoTechFes2015.git
cd TokyoTechFes2015
pip install cv2==1.0
pip install pillow==2.9.7
pip install chainer==1.3.2
pip install matplotlib==1.4.3

Next, unzip dataset.zip and you're ready to go.

unzip dataset.zip

The directory structure of the dataset folder created by decompressing is as follows (only the folder is displayed).

$ tree dataset -d
├── Baysters
├── Buffealoes
├── Carp
├── Dragons
├── Eagles
├── Fighters
├── Giants
├── Hawks
├── Lions
├── Marines
├── Swallows
└── Tigers

I think the names of the 12 baseball teams are lined up. Each folder contains facial images of the players of each team. If you make a prediction with the default settings, it will predict "Which team of the 12 teams the face in the given image is close to the face of the player". What you expect can be changed by changing the dataset folder and below (see below).


  1. First, take a photo of your face with ImageMagick and move the resulting image to an appropriate path.
  2. Enter the following command.
python bbteam_pred.py (path of the image you want to predict)
  1. The captured image will appear on the screen. If the face can be recognized, a frame will be displayed around the face. If not, the script will exit with cannot detect!.
  2. If face recognition is possible, close the image in the displayed frame with the x button on the upper left, and two new screens will appear. One is an image with the text "You belong to (category)!" Written on the face of the image taken, and the other is a bar graph image. The former outputs which category was predicted, and the latter outputs the certainty (posterior probability) of each category.


Here, as an example, suppose that the image ʻeagles_koyama.jpg already in the sample` folder is the image taken in step 1, and you want to make a prediction. eagles_koyama.jpg By the way, this person is Koyama of Rakuten Eagles as the file name suggests.

  1. Enter the following command.
python bbteam_pred.py sample/eagles_koyama.jpg
  1. The captured image will appear on the screen. There is a frame around the face. detected.jpg

  2. When you close the image of the displayed frame with the X button on the upper left, two new screens will appear (one may be hidden in the other window). msg.jpg figure_1.png

From the image above, we can see that Koyama is correctly predicted to be close to the face of the Eagles player, with a 95% certainty. The image below also shows confidence in teams other than Eagles. Besides the Eagles being 95%, the Carp seems to be about 5% confident.

By the way, the same output is also output to the console.

predicted categoriy : Eagles
certainty factor of predicted categoriy : 0.954637289047
certainty factors of each categories : 
Baysters :
Buffealoes :
Carp :
Dragons :
Eagles :
Fighters :
Giants :
Hawks :
Lions :
Marines :
Swallows :
Tigers :


Data set changes

If you want to change what you expect, you need to change the dataset before training. The dataset uses files with a fixed directory structure in the dataset folder for learning and testing. In the default case, as mentioned above, the directory structure is as follows.

$ tree dataset -d
├── Baysters
├── Buffealoes
├── Carp
├── Dragons
├── Eagles
├── Fighters
├── Giants
├── Hawks
├── Lions
├── Marines
├── Swallows
└── Tigers

The name of each directory directly under the dataset folder (Baysters, Buffealoes, ...) represents the category name. By default, Baysters has Baystars in one category.

Images are lined up directly under folders such as Baysters.

$ tree dataset/Baysters 
├── 1000003_ss.jpg
├── 1000007_ss.jpg
├── 1000117_ss.jpg
├── 1000118_ss.jpg
├── 1000119_ss.jpg

These images are face images that belong to their respective categories. Face images of Baystars players are lined up in Baysters. Please change the directory structure referring to the above.

For example, if you want to judge whether it is a man or a woman, do as follows. Save the female face image in Female and the male face image in Male.

$ tree dataset -d
├── Female
└── Male

Execution of learning script

Learning is done with the following command.

python Learning.py (number of data used for learning)(Number of data used for testing)

By default, there are 680 images in the dataset. If you want to use 520 sheets for learning and 120 sheets for testing, do as follows.

python Learning.py 520 130

Recommended Posts

How to use TokyoTechFes2015
How to use xml.etree.ElementTree
How to use Python-shell
How to use tf.data
How to use virtualenv
How to use image-match
How to use shogun
How to use Pandas 2
How to use Virtualenv
How to use numpy.vectorize
How to use pytest_report_header
How to use partial
How to use Bio.Phylo
How to use SymPy
How to use x-means
How to use WikiExtractor.py
How to use IPython
How to use virtualenv
How to use Matplotlib
How to use iptables
How to use numpy
How to use venv
How to use dictionary {}
How to use Pyenv
How to use list []
How to use python-kabusapi
How to use OptParse
How to use return
How to use dotenv
How to use pyenv-virtualenv
How to use Go.mod
How to use imutils
How to use import
How to use Qt Designer
How to use search sorted
[gensim] How to use Doc2Vec
python3: How to use bottle (2)
Understand how to use django-filter
How to use the generator
[Python] How to use list 1
How to use FastAPI ③ OpenAPI
How to use Python argparse
How to use Pandas Rolling
[Note] How to use virtualenv
How to use redis-py Dictionaries
Python: How to use pydub
[Go] How to use "... (3 periods)"
How to use Django's GeoIp2
[Python] How to use input ()
How to use the decorator
[Introduction] How to use open3d
How to use Python lambda
How to use Jupyter Notebook
[Python] How to use virtualenv
python3: How to use bottle (3)
python3: How to use bottle
How to use Google Colaboratory
How to use Python bytes
How to use cron (personal memo)
Python: How to use async with
How to use the zip function