[PYTHON] Face image dataset sorting using machine learning model (# 3)

Overview

Sort UTKFace datasets by the following features. ·no problem ·grayscale ・ Multiple people are shown ・ Processed

Sorting flow

Use Last created learning model to identify the image data in the part1 folder of the UTK Face dataset one by one. ↓ Create the following folder in Google My Drive and save the identified image ・ Normal ・ Grayscale ・ Several ・ Processing

environment

Google Colaboratory(GPU)

#UTKFace part1 ZIP read
z = zipfile.ZipFile('/content/drive/My Drive/part1.zip')
imgfiles = [ x for x in z.namelist() if re.search(r"^part1.*jpg$", x)]

for imgfile in imgfiles:
    image = Image.open(io.BytesIO(z.read(imgfile)))
    image = image.convert('RGB')
    image_p1 = image.resize((im_size, im_size))
    data = np.asarray(image_p1)
    #shape(299,299,3)→(1,299,299,3)Change to
    data = data[None, ...]
    #Get the file name saved in the ZIP folder
    file = str(os.path.basename(imgfile))
    #Predict by inputting data for one image into the trained model
    pred=model.predict(data)
    #Change the location to save the image data according to the determined value
    if np.argmax(pred) == 0:
      image.save('/content/drive/My Drive/normal/' + file)
    elif np.argmax(pred) == 1:
      image.save('/content/drive/My Drive/grayscale/' + file)
    elif np.argmax(pred) == 2:
      image.save('/content/drive/My Drive/several/' + file)
    else :
      image.save('/content/drive/My Drive/processing/' + file)

z.close()
del z, imgfiles

Since model.predict assumes reading of multiple images (model arguments are 4D), an error occurred when trying to predict one by one. He predicted that data = data [None, ...] would convert from 3D to 4D. The image file name is not changed and is sorted and saved in each folder.

Check the images in the sorted folders

(I put a screenshot on it, but I deleted it because I thought it might be illegal.)

grayscale folder

You can see some colored images here and there, but it seems that you can almost distinguish them.

several folders

I was learning with images showing multiple people, but probably because there was little learning data, I feel that images with stuffed animals and animals, or images with a non-simple background are also in this folder. I did.

processing folder

It is possible to almost distinguish data that has characters on the face or a swirl-like pattern.

result

Although the discrimination accuracy is uneven, I was able to collect neat images in the normal folder. I will use this normal folder to create a model that can identify age and gender.

Recommended Posts

Face image dataset sorting using machine learning model (# 3)
Model construction for face image dataset sorting-VGG19 transfer learning (# 2)
Image recognition model using deep learning in 2016
Machine Learning with Caffe -1-Category images using reference model
[Machine learning] Text classification using Transformer model (Attention-based classifier)
I tried to compress the image using machine learning
Machine learning model considering maintainability
Inversely analyze a machine learning model
Deep learning image recognition 2 model implementation
Creating a learning model using MNIST
Application development using Azure Machine Learning
[Machine learning] Summary and execution of model evaluation / indicators (w / Titanic dataset)
Stock price forecast using machine learning (scikit-learn)
[Machine learning] LDA topic classification using scikit-learn
[Machine learning] FX prediction using decision trees
Machine learning
[Machine learning] Supervised learning using kernel density estimation
<Course> Machine Learning Chapter 1: Linear Regression Model
Cross Validation improves machine learning model accuracy
Face image inference using Flask and TensorFlow
<Course> Machine Learning Chapter 2: Nonlinear Regression Model
I made a Dir en gray face classifier using TensorFlow --- ⑦ Learning model
Stock price forecast using machine learning (regression)
Deep learning image recognition 3 after model creation
[Machine learning] Regression analysis using scikit learn
How to create a face image data set used in machine learning (1: Acquire candidate images using WebAPI service)
Machine Learning: Image Recognition of MNIST by using PCA and Gaussian Native Bayes
I tried to implement various methods for machine learning (prediction model) using scikit-learn.
Creating a position estimation model for the Werewolf Intelligence Tournament using machine learning
A story about simple machine learning using TensorFlow
Data supply tricks using deques in machine learning
[Machine learning] Supervised learning using kernel density estimation Part 2
[Machine learning] Supervised learning using kernel density estimation Part 3
[Python3] Let's analyze data using machine learning! (Regression)
Classify machine learning related information by topic model
Implementation of Deep Learning model for image recognition
Try using Jupyter Notebook of Azure Machine Learning
[Machine learning] Extract similar words mechanically using WordNet
Causal reasoning using machine learning (organization of causal reasoning methods)
Inflated learning image
[Memo] Machine learning
Machine learning classification
Machine Learning sample
What I learned about AI / machine learning using Python (1)
Create machine learning projects at explosive speed using templates
I tried learning my own dataset using Chainer Trainer
[Django] Implement image file upload function without using model
What I learned about AI / machine learning using Python (3)
Attempt to include machine learning model in python package
Tech-Circle Let's start application development using machine learning (self-study)
[Machine learning] Try to detect objects using Selective Search
Memo for building a machine learning environment using Python
xgboost: A valid machine learning model for table data
PyTorch Learning Note 2 (I tried using a pre-trained model)
What I learned about AI / machine learning using Python (2)