Giter Site home page Giter Site logo

songhengyang / face_landmark_factory Goto Github PK

View Code? Open in Web Editor NEW
136.0 7.0 41.0 299.71 MB

These are a set of tools using OpenCV, Tensorflow and Keras, with which you can generate your own model of facial landmark detection and demonstrate the effect of newly-generated model easily.

Python 99.76% Shell 0.24%
face landmark tensorflow keras automated annotation detection facial

face_landmark_factory's Introduction

facial-landmark-factory ( Production system of facial landmark detection)

Project Description

[facial-landmark-factory] (https://github.com/songhengyang/face_landmark_factory) is a production system of facial landmark detector written in Python, using Tensorflow r1.13 and subsequent high-level components Keras and Data. Users can use the built-in detection model of this system to process images and video data containing human faces, and conveniently implement functions such as automatic annotation of facial landmark, manual correction of landmark points, conversion of data format, and model training of facial landmark detection. Finally, it is possible to quickly generate a customized model of facial landmark detection suitable for a designated application scenario.

Features

1.This system can automatically detect and collect the frames containing human face in videos, and automatically annotate faces using the built-in models with this production system of facial landmark detection.

2.Using the tools with this system, users can manually correct the points of facial landmark generated by the automatic annotation tool.

3.This system can convert the file format of annotation data, and generate the data that can be recognized by Tensorflow.

4.There are seven mainstream deep learning neural networks with this system. Users can train private data with these neural networks to generate the customized model of facial landmark detection suitable for designated application scenarios.

5.The user can adjust the built-in algorithm, modify these deep learning neural networks, and optimize the effect of facial landmark detection.

Quick Start

To start the test program:

./testing/test_webcam.py

To exit from the test program:

Press q

(Note: test_webcam.py reads the local video file vid.avi by default. If you have a camera with your PC, and want to use the camera as the input source of the test program, you need to modify the value of pamameter "VIDEO_PATH".)

Parameter Description

1.current_model, file of model, such as:

current_model = "../model/facial_landmark_cnn.pb"

2.VIDEO_PATH, video file path, such as:

VIDEO_PATH = "../data/vid.avi" 

or

VIDEO_PATH = 0 

(0 means that the input source is a local camera)

3.CNN_INPUT_SIZE, the height of the network input image (height and width are the same), such as:

CNN_INPUT_SIZE = 64

 

Operating System

1.ubuntu 16.04.2

Dependency

1.tensorflow 1.13

2.keras 2.0 and above

3.opencv 3.4 and above

4.python3

Tutorial

1.Automatic annotation of video files

2.Data Preprocessing

3.Data Training

4.Model Conversion

5.Model Testing

  • ./data_generate/video_auto_label.py

    This tool reads the video file, with the built-in models of facial landmark detection in this system, recognizes image of faces appearing in the frames, automatically annotates face landmarks, generates files in pts format, the files of facial image and the files of dimension in pts format are stored in a same directory.

Parameter Description

MODEL_FILE, the file of face landmark detection model, such as:

MODEL_FILE = "../model/facial_landmark_MobileNet.pb"

VIDEO_PATH, file of the video, such as:

VIDEO_PATH = "../data/IU.avi"

OUTPUT_DIR, the directory storing the files of facial image and the files of pts format annotation, such as:

OUTPUT_DIR = "../data/out"

CNN_INPUT_SIZE, input image size of neural network, height and width are the same, such as:

CNN_INPUT_SIZE = 64
  • ./data_generate/from_pts_to_json_box_image.py

    This tool reads files of annotation data in pts format, calculates the dimensions of the generated facial box, and then records the dimensions of facial box and the facial annotation data into the files of facial box dimension and the files of facial landmark in json format.

Parameter Description

INPUT_LIST, the list of directories storing pts annotation files, such as:

INPUT_LIST = ["../data/out"]

OUTPUT_DIR, the directory storing files of the facial box dimensions and the files of facial landmarks in json format, such as:

OUTPUT_DIR = "../data/json"
  • ./data_generate/manual_correct_label.py

    This tool can help to modify the dimensions of the facial landmark manually. This tool reads files of original image, files of facial box dimensions in jason format, and files of facial landmark, and display images of the facial box and landmarks that has been marked. Users can modify dimensions of the landmark with a keyboard. Facial landmarks are manually corrected, and files with modified facial dimensions and face landmarks are generated finally.      Parameter Description

INPUT_DIR, the directory storing files of facial dimensions and the files of facial landmarks, such as:      INPUT_DIR = "../data/json"

Instructions for correcting the facial landmarks with keyboard (requires activation of the window by click the right button):

Skip to the file of next image:

Press space

Back to the file of previous image:

Press b

Shift to the last point:

Press q

Shift to the next point:

Press e

Move one pixel to left:

Press a

Move one pixel to right:

Press d

Move one pixel to upper:

Press w

Move one pixel to lower:

Press s

To exit from program:

Press Esc
  • ./data_generate/gen_argment.py

    This tool reads a limited number of facial images and generate augment datasets based on rules to improve model training. This tool reads files of facial image and files of facial landmark in a given directory, and generates an augment dataset according to the built-in rules of the tool. Training with augment datasets can greatly improve the training effect of deep learning neural networks and generate an optimized facial landmark detection model.

Parameter Description

INDIR_LIST, the list of directory storing files of facial image and files of the facial landmark in jason format, such as:

INDIR_LIST = ["../data/json","../data/json01"]

OUTPUT_DIR, the directory storing the files of augment datasets, such as:

OUTPUT_DIR = "../data/augment"
  • ./data_generate/gen_tfrecord.py

    This tool reads the dataset of a given directory and generates files in tfrecords format for tensorflow training.

input_list, a list fo directories storing data sets, such as:

input_list = ["../data/json","../data/json01"]

tfrecord_file_dir, the directory storing files in tfrecords format generated by this tool, such as:

tfrecord_file_dir = "../data/tfrecord"

Index_extract, used to generate a list of face landmark numbers in the file of tfrecords format. The empty list means to extract all points, such as:

index_extract = []
  • ./training/train_models.py

    This tool reads the training data sets of the tfrecord format in the given directory, trains and generates the facial landmark detection model with the user-selected neural network (total of 7 types). The model format is h5 (keras can read).

DATA_DIR, directory storing training data in tfrecord format, such as:

DATA_DIR = "../data/tfrecord"

LOADING_PRETRAIN, pre-training switch (True/False), such as:

LOADING_PRETRAIN = False

BATCH_SIZE, BATCH, such as:

BATCH_SIZE = 10

STEPS_PER_EPOCH, the amount of training data, such as:

STEPS_PER_EPOCH = 100

TEST_STEPS, the number of test data, such as:

TEST_STEPS = 11

EPOCHS, training iterations, such as:

EPOCHS = 1000

IMAGE_SIZE, image pixel value (length and width values are the same), such as:

IMAGE_SIZE = 64

(Note: Tool training newly generated facial landmark detection model file path: ../model/facial_landmark_SqueezeNet.h5)

###Model Conversion

  • ./model_converter/h5_to_pb.py,

    The tool converts h5 model files into pb model files, showing input and output layer names.

  • ./model_converter/to_tflite.sh,

    This tool converts pb model files into tflite model files.

  • ./testing/test_webcam.py

Generated pb format model can be used to test the facial landmark detection model training effect.

To start test program:

./testing/test_webcam.py

To exit from test program:

Press q

References

  1. https://github.com/yinguobing/cnn-facial-landmark

  2. https://some.other.site/subdir/

Copyright

Thanks

face_landmark_factory's People

Contributors

songhengyang avatar xuansan915 avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

face_landmark_factory's Issues

Bug in augment script

Thanks for the good work!

Why does gen_augment.py produce a bigger test_tfrecord than train_tfrecord. I believe the test_tfrecord is supposed to be the train_tfrecord.

train color image

hello author,

how can i train color images. i used is_gray = False while generating tf record file. but i get error while training the model

tensorflow.python.framework.errors_impl.InvalidArgumentError: Input to reshape is a tensor with 12288 values, but the requested shape has 4096
[[{{node Reshape}}]]
[[{{node IteratorGetNext}}]]

data augmentation

hello author,

the data augmentation generates the tf records, but the images and landmark folders are empty. can you help

thank you

difference between landmark tensorflow implementation and openpose/tfpose for human pose estimation

hello author,

i have a query, how is this implementation different from tfpose which uses coco dataset and mobilenet model. i think this model predicts all the points even if some face parts are missing( if i cover my eyes or nose) it still detects right?
but it openpose/tf-pose if we cover the body parts, it wont show the keypoints. how is this different, can you give me some advice.

thank you

correct_pad

In mobile_net_v2.py line 83 "from . import correct_pad" , where is this file? Thanks

如何在300w数据集上测试?

感谢分享,我想请问一下,如果我使用300w数据集对网络进行训练,那如何使用300W测试集来测试精度?比如NME?期待您的回复

Image preprocessing

Thanks for the high quality code, really nice setup!

I have a question related to the image preprocessing.
It seems that you never use the "preprocess_input" functions
So I guess you expect image between 0 and 255: It may reduce performance.

Furthermore when I use the facial_landmark_SqueezeNet network, the predictions do not really take into account the input.

I highly suspect the 2 problems to be related.

Thanks in advance

Introduction

If you want to generate a facial landmark model, that is it. This set of tools is very easy to use, you can train a model by yourself, test the model and get the result immediately.

Custom dataset and points

@songhengyang @xuansan915 Hi thanks for an wonderful code , i had few queries

  1. Can train this more number of points like 192,168... etc . What all changes i have to make it run
  2. Can i train it on custom dataset , how many ideal number o fimages should i require to get good accuracy

thansk in advance

Loading MobileNet has problem perhaps with the version inconsistency

Hello, my tensorflow version is 1.13rc0, keras version is 2.2.4 and opencv-version is 4.1.2. It is good when loading bigger cnn and squeezenet, but failed when loading mobilenet hdf5 file.
It reported:

Traceback (most recent call last):
File "test_webcam.py", line 81, in
webcam_main()
File "test_webcam.py", line 21, in webcam_main
mark_detector = MarkDetector(current_model, CNN_INPUT_SIZE)
File "E:\PythonSpace\face_landmark_factory-keras\face_landmark_factory-master\testing\mark_detector.py", line 46, in init
self.sess = tf.keras.models.load_model(mark_model)
File "E:\Users\admin\Anaconda3\envs\py3.6\lib\site-packages\tensorflow\python\keras\engine\saving.py", line 234, in load_model
model = model_from_config(model_config, custom_objects=custom_objects)
File "E:\Users\admin\Anaconda3\envs\py3.6\lib\site-packages\tensorflow\python\keras\engine\saving.py", line 324, in model_from_config
return deserialize(config, custom_objects=custom_objects)
File "E:\Users\admin\Anaconda3\envs\py3.6\lib\site-packages\tensorflow\python\keras\layers\serialization.py", line 64, in deserialize
printable_module_name='layer')
File "E:\Users\admin\Anaconda3\envs\py3.6\lib\site-packages\tensorflow\python\keras\utils\generic_utils.py", line 192, in deserialize_keras_object
list(custom_objects.items())))
File "E:\Users\admin\Anaconda3\envs\py3.6\lib\site-packages\tensorflow\python\keras\engine\network.py", line 1263, in from_config
process_layer(layer_data)
File "E:\Users\admin\Anaconda3\envs\py3.6\lib\site-packages\tensorflow\python\keras\engine\network.py", line 1249, in process_layer
layer = deserialize_layer(layer_data, custom_objects=custom_objects)
File "E:\Users\admin\Anaconda3\envs\py3.6\lib\site-packages\tensorflow\python\keras\layers\serialization.py", line 64, in deserialize
printable_module_name='layer')
File "E:\Users\admin\Anaconda3\envs\py3.6\lib\site-packages\tensorflow\python\keras\utils\generic_utils.py", line 194, in deserialize_keras_object
return cls.from_config(cls_config)
File "E:\Users\admin\Anaconda3\envs\py3.6\lib\site-packages\keras\engine\base_layer.py", line 1109, in from_config
return cls(**config)
File "E:\PythonSpace\face_landmark_factory-keras\face_landmark_factory-master\testing\utils.py", line 69, in init
self.depthwise_initializer = initializers.get(depthwise_initializer)
File "E:\Users\admin\Anaconda3\envs\py3.6\lib\site-packages\keras\initializers.py", line 508, in get
return deserialize(identifier)
File "E:\Users\admin\Anaconda3\envs\py3.6\lib\site-packages\keras\initializers.py", line 503, in deserialize
printable_module_name='initializer')
File "E:\Users\admin\Anaconda3\envs\py3.6\lib\site-packages\keras\utils\generic_utils.py", line 138, in deserialize_keras_object
': ' + class_name)
ValueError: Unknown initializer: GlorotUniform

How can I try to fix problem and load mobilenet for testing?

Thanks & Regards!

训练的时候报错

history = parallel_model.fit(.......)这句话报错

AttributeError: 'BatchDataset' object has no attribute 'ndim'

....

老哥,你这是神经网络直接输出68个点的坐标吗?我看了一下train_models.py的代码,发现好像只是简单的回归预测一下?谢谢回答哈

loss function error

hello author,

i get some error while training. please help.

edit: the images and landmark folders are empty while generating tfrecords. is it okay? but i get the train and validation tfrecords.

File "/home/rahul/rahul/face_landmark_factory-master/testing/utils.py", line 21, in smoothL1
x = K.switch(x < HUBER_DELTA, 0.5 * x ** 2, HUBER_DELTA * (x - 0.5 * HUBER_DELTA))

File "/home/rahul/anaconda3/envs/tensorflow/lib/python3.7/site-packages/tensorflow/python/framework/ops.py", line 1867, in _create_c_op
raise ValueError(str(e))
ValueError: Shape must be rank 0 but is rank 2 for 'loss/output_loss/cond/Switch' (op: 'Switch') with input shapes: [?,136], [?,136].

thank you

训练报错

请问训练是报错 val_loss did not improve from 161.33531并且报错KeyError: 'loss'是怎么回事呀,我直接预处理完成后运行的train_model.py

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.