Giter VIP home page Giter VIP logo

tiny_faces_in_tensorflow's Introduction

Tiny Face Detector in TensorFlow

A TensorFlow port(inference only) of Tiny Face Detector from authors' MatConvNet codes[1].

Requirements

Codes are written in Python. At first install Anaconda. Then install OpenCV, TensorFlow.

Usage

Converting a pretrained model

matconvnet_hr101_to_pickle reads weights of the MatConvNet pretrained model and write back to a pickle file which is used in a TensorFlow model as initial weights.

  1. Download a ResNet101-based pretrained model(hr_res101.mat) from the authors' repo.

  2. Convert the model to a pickle file by:

python matconvnet_hr101_to_pickle.py 
        --matlab_model_path /path/to/pretrained_model 
        --weight_file_path  /path/to/pickle_file

Tesing Tiny Face Detector in TensorFlow

  1. Prepare images in a directory.

  2. tiny_face_eval.py reads images one by one from the image directory and write images to an output directory with bounding boxes of detected faces.

python tiny_face_eval.py
  --weight_file_path /path/to/pickle_file
  --data_dir /path/to/input_image_directory
  --output_dir /path/to/output_directory

Neural network diagram

This(pdf) is a network diagram of the ResNet101-based model used here for an input image(height: 1150, width: 2048, channel: 3).

Examples

Though this model is developed to detect tiny faces, I apply this to several types of images including 'faces' as experiments.

selfie with many people

This is the same image as one in the authors' repo[1].

selfie

Original image

selfie of celebrities

selfie

Original image

selfie of "celebrities"

Homer and "Meryl Streep" are missed.

selfie

Original image

zombies

selfie

Original image

monkeys

selfie

Original image

dogs

selfie

Original image

cats

selfie

Original image

figure1 from a paper[2]

selfie

figure8 from a paper[2].

Facebook's face detector failed to detect these faces(as of the paper publication date[14 Feb 2016]).

selfie

figure3 from a paper[2]

selfie

figure6 from a paper[2]

selfie

Acknowledgments

Disclaimer

Codes are tested only on CPUs, not GPUs.

References

  1. Hu, Peiyun and Ramanan, Deva, Finding Tiny Faces, The IEEE Conference on Computer Vision and Pattern Recognition (CVPR 2017). project page, arXiv

  2. Michael J. Wilber, Vitaly Shmatikov, Serge Belongie, Can we still avoid automatic face detection, 2016. arXiv

tiny_faces_in_tensorflow's People

Contributors

cydonia999 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tiny_faces_in_tensorflow's Issues

Libraries Version

I am trying to implement this on a Jupyter notebook but there are several warnings as well as errors mostly due to compatibility of libraries.
Does python 3.6 or python 2.7 here make a difference?
Could anyone please specify the versions of all the libraries.

Thank You.

pl.frange no longer usable

hey, i tried to run the cloned code and it wouldnt work bcs pls.frange no longer exists as a function in pylab, i replaced the 2 occurences with np.arange and everything seemed to work ok

Traceback (most recent call last):
File "tiny_face_eval.py", line 227, in
main()
File "tiny_face_eval.py", line 224, in main
lw=args.line_width, display=args.display)
File "tiny_face_eval.py", line 121, in evaluate
scales = _calc_scales()
File "tiny_face_eval.py", line 115, in _calc_scales
scales_down = pl.frange(min_scale, 0, 1.)
AttributeError: module 'pylab' has no attribute 'frange'

Implement training code

Hi,

This is a very nice work. It helps my research a lot. However, when I try to implement training part based on your architecture, it counters with lots of problems. Therefore, will you implement training part and release in the future? I think it will help many people as well. Thx!

Can use ResNet 50?

If I want to use hr_res50.mat, how can i revised the code "matconvnet_hr101_to_pickle.py" and "tiny_face_model.py" ?

thank you

slower and slower in testing model?

Hi, I run the code with a problem that it runs slower and slower for a few images.
I found the function of tf.image.non_max_suppression may cause this problem, and I rewrite nms instead to slove this problem.

ImportError: bad magic number in 'pickle'

Traceback (most recent call last):
File "tiny_face_eval.py", line 6, in
import tensorflow as tf
File "/Users/nicksonmbwavi/anaconda3/envs/mypython3/lib/python3.6/site-packages/tensorflow/init.py", line 22, in
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File "/Users/nicksonmbwavi/anaconda3/envs/mypython3/lib/python3.6/site-packages/tensorflow/python/init.py", line 47, in
import numpy as np
File "/Users/nicksonmbwavi/anaconda3/envs/mypython3/lib/python3.6/site-packages/numpy/init.py", line 142, in
from . import add_newdocs
File "/Users/nicksonmbwavi/anaconda3/envs/mypython3/lib/python3.6/site-packages/numpy/add_newdocs.py", line 13, in
from numpy.lib import add_newdoc
File "/Users/nicksonmbwavi/anaconda3/envs/mypython3/lib/python3.6/site-packages/numpy/lib/init.py", line 8, in
from .type_check import *
File "/Users/nicksonmbwavi/anaconda3/envs/mypython3/lib/python3.6/site-packages/numpy/lib/type_check.py", line 11, in
import numpy.core.numeric as _nx
File "/Users/nicksonmbwavi/anaconda3/envs/mypython3/lib/python3.6/site-packages/numpy/core/init.py", line 38, in
from . import numeric
File "/Users/nicksonmbwavi/anaconda3/envs/mypython3/lib/python3.6/site-packages/numpy/core/numeric.py", line 43, in
import pickle
ImportError: bad magic number in 'pickle': b'\x80\x04\x95\x0f'

questions about context

In this paper"finding tiny face", I find author use foveal structure to find small face, but in your project I can't find any code about context.

about argument parse

Thanks for sharing, but I still have some questions about "matconvnet_hr101_to_pickle.py" to ask you.

First, I can not run it successfully even though I've downloaded "hr_res101.mat" but it still throws "AssertionError: Matlab pretrained model: /path/to/hr_res101.mat not found". I learned about the usage of ArgumentParser, but I did not solve it. If you can give me some help, I would be greatly appreciated.

Second, I do not know much about matlab, so I can not understand the code, such as "clusters = np.copy (net ['meta'] [0] [0] [0] [0] [6])". More precisely, I think "layers = net ['layers']" is correct, but why use "layers = net [' layers'] [0] [0] [0]". Further more, I think "layer_name" and "layer_type" are just a string, but why do you put all the data into layer_inputs and layer_outputs?

Third, what does "weight_file" mean? Can you elaborate on the data you wrote in the weight_file file?

Maybe you think I asked the questions are stupid, yes, I admit, but who have not experienced such a stage? Thanks very much for sharing, and I will be even more grateful if you can help me with these questions.

Eval resized image

Hi @cydonia999,

First, thank you for your work.
I try to detect the face with resized image (512x512x3). I added the cv2.resize function to your code but the result was not as expected. The bbx does not cover exactly the face as shown in followed images, original resolution and resized respectively.

#  line  105 - 117 in  tiny_face_eval.py

with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())

    for filename in filenames:
      fname = filename.split(os.sep)[-1]
      raw_img = cv2.imread(filename)
      raw_img = cv2.cvtColor(raw_img, cv2.COLOR_BGR2RGB)
      raw_img = cv2.resize(raw_img, (img_width, img_height))     <<<<<<<<   RESIZE IMAGE (512x512x3)
      raw_img_f = raw_img.astype(np.float32)

      def _calc_scales():
        raw_h, raw_w = raw_img.shape[0], raw_img.shape[1]
        min_scale = min(np.floor(np.log2(np.max(clusters_w[normal_idx] / raw_w))),
                        np.floor(np.log2(np.max(clusters_h[normal_idx] / raw_h))))

Do you have any suggest to how can I get the the result as original resolution image?
Thank you.

0000000005
0000000005
0000000045
0000000045

test model with picture

Thanks for sharing this project. When I used this model to test, I found that when the proportion of human face was greater than a certain value, the face could not be detected. Could you tell me the specific value?

TypeError: __init__() got an unexpected keyword argument 'dtype'

So, I am getting a TypeError in tiny_face_model.py line 44 ,Kindly help me with this
WARNING:tensorflow:From /usr/local/lib/python3.7/dist-packages/tensorflow/python/compat/v2_compat.py:101: disable_resource_variables (from tensorflow.python.ops.variable_scope) is deprecated and will be removed in a future version. Instructions for updating: non-resource variables are not supported in the long term Traceback (most recent call last): File "tiny_face_eval.py", line 229, in <module> main() File "tiny_face_eval.py", line 226, in main lw=args.line_width, display=args.display) File "tiny_face_eval.py", line 85, in evaluate score_final = model.tiny_face(x) File "/content/drive/My Drive/Tiny_Faces_in_Tensorflow/tiny_face_model.py", line 207, in tiny_face conv = self.conv_block(img, 'conv1', shape=[7, 7, 3, 64], strides=[1, 2, 2, 1], padding="VALID", add_relu=True) File "/content/drive/My Drive/Tiny_Faces_in_Tensorflow/tiny_face_model.py", line 126, in conv_block weight = self._weight_variable_on_cpu(name, shape) File "/content/drive/My Drive/Tiny_Faces_in_Tensorflow/tiny_face_model.py", line 44, in _weight_variable_on_cpu initializer = tf.constant_initializer(weights, dtype=self.dtype) TypeError: __init__() got an unexpected keyword argument 'dtype'

About the speed

@cydonia999
Amazing working! This is the most accurate Face detecting project I have used .
But speed is a little slow.
is there any params I can use for increase the speed of detecting?
my mac pro spend 200 seconds to handle a 2880*1680 pic(5M byte).
Is there any params settings or method of modify source code to ignore too small and too big scale to scan? I think ignore too small and too big scale can increase speed for me
Thank you !!

AttributeError: module 'pylab' has no attribute 'frange'

/home/xinan/.conda/envs/ssh/bin/python3.6 /home/xinan/PycharmProjects/2.Tiny_Faces_in_Tensorflow-master/tiny_face_eval.py
/home/xinan/.conda/envs/ssh/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:469: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_qint8 = np.dtype([("qint8", np.int8, 1)])
/home/xinan/.conda/envs/ssh/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:470: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_quint8 = np.dtype([("quint8", np.uint8, 1)])
/home/xinan/.conda/envs/ssh/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:471: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_qint16 = np.dtype([("qint16", np.int16, 1)])
/home/xinan/.conda/envs/ssh/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:472: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_quint16 = np.dtype([("quint16", np.uint16, 1)])
/home/xinan/.conda/envs/ssh/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:473: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_qint32 = np.dtype([("qint32", np.int32, 1)])
/home/xinan/.conda/envs/ssh/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:476: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
np_resource = np.dtype([("resource", np.ubyte, 1)])
2019-12-17 10:09:57.123683: I tensorflow/core/platform/cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
Traceback (most recent call last):
File "/home/xinan/PycharmProjects/2.Tiny_Faces_in_Tensorflow-master/tiny_face_eval.py", line 227, in
main()
File "/home/xinan/PycharmProjects/2.Tiny_Faces_in_Tensorflow-master/tiny_face_eval.py", line 224, in main
lw=args.line_width, display=args.display)
File "/home/xinan/PycharmProjects/2.Tiny_Faces_in_Tensorflow-master/tiny_face_eval.py", line 121, in evaluate
scales = _calc_scales()
File "/home/xinan/PycharmProjects/2.Tiny_Faces_in_Tensorflow-master/tiny_face_eval.py", line 115, in _calc_scales
scales_down = pl.frange(min_scale, 0, 1.)
AttributeError: module 'pylab' has no attribute 'frange'

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.