Git Product home page Git Product logo

pytorch-pcn's Introduction

PCN in Pytorch

中文版.

Progressive Calibration Networks (PCN) is an accurate rotation-invariant face detector running at real-time speed on CPU. This is an implementation for PCN.

This is a pytorch implementation version of the original repo

Getting Started

A separate Python environment is recommended.

  • Python3.5+ (Python3.5, Python3.6 are tested)
  • Pytorch == 1.0
  • opencv4 (opencv3.4.5 is tested also)
  • numpy

install dependences using pip

pip3 install numpy opencv-python
pip3 install https://download.pytorch.org/whl/cpu/torch-1.0.1.post2-cp36-cp36m-linux_x86_64.whl
pip3 install torchvision (optional)

or install using conda

conda install opencv numpy
conda install pytorch-cpu torchvision-cpu -c pytorch

Usage

cd pytorch-PCN
python demo.py path/to/image 

or use webcam demo

python webcam.py

Install

cd pytorch-PCN && pip install .

Results

More results can be found in result directory, or you can run the script to generate them.

There is still one image failed. Pull requests to fix it is welcome.

License

This code is distributed under the BSD 2-Clause license.

Citing & Thanks

@inproceedings{shiCVPR18pcn,
    Author = {Xuepeng Shi and Shiguang Shan and Meina Kan and Shuzhe Wu and Xilin Chen},
    Title = {Real-Time Rotation-Invariant Face Detection with Progressive Calibration Networks},
    Booktitle = {The IEEE Conference on Computer Vision and Pattern Recognition (CVPR)},
    Year = {2018}
}

Wishes

For anyone who hear, see, think about or use this repo, I hope them gain temporary happiness and everlasting happiness

pytorch-pcn's People

Contributors

siriusdemon 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

pytorch-pcn's Issues

Does img_resized should be changed in each loop?

I compare the origin repo with yours.

function ./pcn/pcn.py/stage1(img, imgPad, net, thres) line164.img_resized is changed by function preprocess_img in each loop. Is it correct?

I don't know whether the operator in the original repo img.convertTo(imgF, CV_32FC3); return imgF - mean; changes the source matrix img, but your code changes it. After the third loop, under most circumstances, np.max(img_resized) will be a negative integer.

Thank you.

Can't install with pip

root@ada39ed4587c:/app/pytorch-PCN# pip3 install .
WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see pypa/pip#5599 for advice on fixing the underlying issue.
To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
Processing /app/pytorch-PCN
ERROR: Command errored out with exit status 1:
command: /usr/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-req-build-8u7yr5ph/setup.py'"'"'; file='"'"'/tmp/pip-req-build-8u7yr5ph/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-req-build-8u7yr5ph/pip-egg-info
cwd: /tmp/pip-req-build-8u7yr5ph/
Complete output (7 lines):
Traceback (most recent call last):
File "", line 1, in
File "/tmp/pip-req-build-8u7yr5ph/setup.py", line 4, in
long_description = f.read()
File "/usr/lib/python3.6/encodings/ascii.py", line 26, in decode
return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in position 19: ordinal not in range(128)
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

I get this error constantly. It seems like non ascii character in README.md

Do you have time to help me? sir

hello sir
I don't know how to use this model. Can you give me a way to use it
An error occurred while calling the method and cannot be used. Can you help me

How to train on new dataset

Hi, nice work. How about retraining on a new dataset? Because I find that the pre-trained PCN performs badly on low-resolution images.

Very strange processing sequence in stage1

This is the loop for your stage1 which invokes first model repeatedly:

def stage1(img, imgPad, net, thres):
    row = (imgPad.shape[0] - img.shape[0]) // 2
    col = (imgPad.shape[1] - img.shape[1]) // 2
    winlist = []
    netSize = 24
    curScale = minFace_ / netSize
    img_resized = resize_img(img, curScale)
    while min(img_resized.shape[:2]) >= netSize:
        img_resized = preprocess_img(img_resized)   <---------------- !!!
        # net forward
        net_input = set_input(img_resized)
        with torch.no_grad():
            net.eval()
            cls_prob, rotate, bbox = net(net_input)

        w = netSize * curScale
        for i in range(cls_prob.shape[2]): # cls_prob[2]->height
            for j in range(cls_prob.shape[3]): # cls_prob[3]->width
                if cls_prob[0, 1, i, j].item() > thres:
                    sn = bbox[0, 0, i, j].item()
                    xn = bbox[0, 1, i, j].item()
                    yn = bbox[0, 2, i, j].item()
                    rx = int(j * curScale * stride_ - 0.5 * sn * w + sn * xn * w + 0.5 * w) + col
                    ry = int(i * curScale * stride_ - 0.5 * sn * w + sn * yn * w + 0.5 * w) + row
                    rw = int(w * sn)
                    if legal(rx, ry, imgPad) and legal(rx + rw - 1, ry + rw -1, imgPad):
                        if rotate[0, 1, i, j].item() > 0.5:
                            winlist.append(Window2(rx, ry, rw, rw, 0, curScale, cls_prob[0, 1, i, j].item()))
                        else:
                            winlist.append(Window2(rx, ry, rw, rw, 180, curScale, cls_prob[0, 1, i, j].item()))
        img_resized = resize_img(img_resized, scale_)  <---------------- !!!
        curScale = img.shape[0] / img_resized.shape[0]
    return winlist

I have marked repeated application of preprocess_img to img_resized. This function subtracts mean all the time so you can check that image mean shifts towards big negative numbers:

def preprocess_img(img, dim=None):
    if dim:
        img = cv2.resize(img, (dim, dim), interpolation=cv2.INTER_NEAREST)
    return img - np.array([104, 117, 123])

But you infer through the same network all the time, so this isn't possible that you have to feed different inputs.

I have moved preprocessing out of the loop, and the result is still ok. Is it a bug?

number of images

hi
what changes in code required to check several numbers of images output in one go.
not only one image

a question about GPU running

Hello. I tested it on the GPU, and it slowed down a lot. After debugging, I found that pcn.py→def stage1(),These two double "for" take a lot of time.
for i in range(cls_prob.shape[2]): # cls_prob[2]->height
for j in range(cls_prob.shape[3]): # cls_prob[3]->width
I've put net_input into the GPU, corresponding, CLS_ Prob, rotate and bbox are also loaded into the GPU.these two “for” need changed???
Or I use GPU in the wrong way. Can you help me

您好,我尝试了用gpu运行,速度变慢了。经过调试,我发现是pcn.py→def stage1()函数中的这个双for循环 占用了大量的时间,比在cpu上还要更久。
for i in range(cls_prob.shape[2]): # cls_prob[2]->height
for j in range(cls_prob.shape[3]): # cls_prob[3]->width
我把模型加载到了gpu,把net_input也加载到了gpu ,相应的CLS_ Prob, rotate and bbox都在gpu,这两句for有需要改的么。
还是说我使用gpu的方式不对呢?你可以帮帮我么

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.