Code Monkey home page Code Monkey logo

faceboxes-tensorflow's Introduction

introduction

A tensorflow 2.0 implement faceboxes.

CAUTION: this is the tensorflow2 branch, if you need to work on tensorflow1, please switch to tf1 branch

And some changes has been made in RDCL module, to achieve a better performance and run faster:

  1. input size is 512 (1024 in the paper), then the first conv stride is 2, kernel size 7x7x12.
  2. replace the first maxpool by conv 3x3x24 stride 2
  3. replace the second 5x5 stride2 conv and maxpool by two 3x3 stride 2 conv
  4. anchor based sample is used in data augmentaion.

codes like below

    with tf.name_scope('RDCL'):
     net = conv2d(net_in, 12, [7, 7], stride=2,activation_fn=tf.nn.relu, scope='init_conv1')
     net = conv2d(net, 24, [3, 3], stride=2, activation_fn=tf.nn.crelu, scope='init_conv2')
    
     net = conv2d(net, 32, [3, 3], stride=2,activation_fn=tf.nn.relu,scope='conv1x1_before1')
     net = conv2d(net, 64, [3, 3], stride=2, activation_fn=tf.nn.crelu, scope='conv1x1_before2')
     
     return net

I want to name it faceboxes++ ,if u don't mind

Pretrained model can be download from:

Evaluation result on fddb

fddb

fddb
0.96

Speed: it runs over 70FPS on cpu (i7-8700K), 30FPS (i5-7200U), 140fps on gpu (2080ti) with fixed input size 512, tf2.0, multi thread. And i think the input size, the time consume and the performance is very appropriate for application :)

Hope the codes can help you, contact me if u have any question, [email protected] .

requirment

  • tensorflow2.0

  • tensorpack (data provider)

  • opencv

  • python 3.6

useage

train

  1. download widerface data from http://shuoyang1213.me/WIDERFACE/ and release the WIDER_train, WIDER_val and wider_face_split into ./WIDER,

  2. download fddb, and release FDDB-folds into ./FDDB , 2002,2003 into ./FDDB/img

  3. then run python prepare_data.pyit will produce train.txt and val.txt

    (if u like train u own data, u should prepare the data like this: ...../9_Press_Conference_Press_Conference_9_659.jpg| 483(xmin),195(ymin),735(xmax),543(ymax),1(class) ...... one line for one pic, caution! class should start from 1, 0 means bg)

  4. then, run:

    python train.py

    and if u want to check the data when training, u could set vis in train_config.py as True

finetune

  1. (if u like train u own data, u should prepare the data like this: ...../9_Press_Conference_Press_Conference_9_659.jpg| 483(xmin),195(ymin),735(xmax),543(ymax),1(class) ...... one line for one pic, caution! class should start from 1, 0 means bg)

  2. set config.MODEL.pretrained_model='./model/detector/variables/variables', in train_config.py, and the model dir structure is :

    ./model/
    ├── detector
    │   ├── saved_model.pb
    │   └── variables
    │       ├── variables.data-00000-of-00001
    │       └── variables.index
    
  3. adjust the lr policy

  4. python train.py

evaluation

    python test/fddb.py [--model [TRAINED_MODEL]] [--data_dir [DATA_DIR]]
                          [--split_dir [SPLIT_DIR]] [--result [RESULT_DIR]]
    --model              Path of the saved model,default ./model/detector
    --data_dir           Path of fddb all images
    --split_dir          Path of fddb folds
    --result             Path to save fddb results

example python model_eval/fddb.py --model model/detector --data_dir 'FDDB/img/' --split_dir FDDB/FDDB-folds/ --result 'result/'

visualization

A demo

  1. python vis.py --img_dir your_images_dir --model model/detector

  2. or use a camera: python vis.py --cam_id 0 --model model/detector

You can check the code in vis.py to make it runable, it's simple.

reference

faceboxes-tensorflow's People

Contributors

610265158 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

Watchers

 avatar  avatar  avatar  avatar

faceboxes-tensorflow's Issues

Both tf1.14 and tf2.0 version hang during training

Hi @610265158, I tried to train FaceBoxes detectors using your implementation. However, both tf1.14 and tf2.0 version hang after training started several hundred iterations. No error messages but losses stopped updating. Do you have any idea what might be the cause? Thank you so much!

tflite 版本问题

作者你好,你的模型不错,感谢你的开源精神。我尝试使用你的模型去转为tflite的时候遇到的麻烦,转换器貌似不支持一些ops,报错如下

2021-04-08 15:37:58.650532: I tensorflow/compiler/jit/xla_gpu_device.cc:99] Not creating XLA devices, tf_xla_enable_xla_devices not set
loc(callsite(callsite("map/TensorArrayV2_2@__inference_inference_5346" at "StatefulPartitionedCall@__inference_signature_wrapper_5514") at "StatefulPartitionedCall")): error: requires element_shape to be 1D tensor during TF Lite transformation pass
loc(callsite(callsite("map/TensorArrayV2_2@__inference_inference_5346" at "StatefulPartitionedCall@__inference_signature_wrapper_5514") at "StatefulPartitionedCall")): error: failed to legalize operation 'tf.TensorListReserve' that was explicitly marked illegal
Traceback (most recent call last):
  File "D:\python\lib\site-packages\tensorflow\lite\python\convert.py", line 213, in toco_convert_protos
    enable_mlir_converter)
  File "D:\python\lib\site-packages\tensorflow\lite\python\wrap_toco.py", line 38, in wrapped_toco_convert
    enable_mlir_converter)
Exception: <unknown>:0: error: loc(callsite(callsite("map/TensorArrayV2_2@__inference_inference_5346" at "StatefulPartitionedCall@__inference_signature_wrapper_5514") at "StatefulPartitionedCall")): requires element_shape to be 1D tensor during TF Lite transformation pass
<unknown>:0: note: loc("StatefulPartitionedCall"): called from
<unknown>:0: error: loc(callsite(callsite("map/TensorArrayV2_2@__inference_inference_5346" at "StatefulPartitionedCall@__inference_signature_wrapper_5514") at "StatefulPartitionedCall")): failed to legalize operation 'tf.TensorListReserve' that was explicitly marked illegal
<unknown>:0: note: loc("StatefulPartitionedCall"): called from


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "convert_tflite_model.py", line 9, in <module>
    tflite_model = converter.convert()
  File "D:\python\lib\site-packages\tensorflow\lite\python\lite.py", line 739, in convert
    result = _convert_saved_model(**converter_kwargs)
  File "D:\python\lib\site-packages\tensorflow\lite\python\convert.py", line 637, in convert_saved_model
    enable_mlir_converter=True)
  File "D:\python\lib\site-packages\tensorflow\lite\python\convert.py", line 216, in toco_convert_protos
    raise ConverterError(str(e))
tensorflow.lite.python.convert.ConverterError: <unknown>:0: error: loc(callsite(callsite("map/TensorArrayV2_2@__inference_inference_5346" at "StatefulPartitionedCall@__inference_signature_wrapper_5514") at "StatefulPartitionedCall")): requires element_shape to be 1D tensor during TF Lite transformation pass
<unknown>:0: note: loc("StatefulPartitionedCall"): called from
<unknown>:0: error: loc(callsite(callsite("map/TensorArrayV2_2@__inference_inference_5346" at "StatefulPartitionedCall@__inference_signature_wrapper_5514") at "StatefulPartitionedCall")): failed to legalize operation 'tf.TensorListReserve' that was explicitly marked illegal
<unknown>:0: note: loc("StatefulPartitionedCall"): called from

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.