Code Monkey home page Code Monkey logo

pedestrian_recognition's Introduction

pedestrian_recognition

A simple human recognition api for re-ID usage, power by paper In Defense of the Triplet Loss for Person Re-Identification and MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications

Testing Environment

Operating system

  1. MacOS Sierra
  2. Ubuntu 16.04

Python package (Python 3.5 or Python3.6)

  1. Tensorflow 1.8
  2. opencv 3.3 (Need opencv dnn library)
  3. Numpy
  • Install package with requirements.txt file
pip install -r requirements.txt

Prepare the model

Since we are using third-party pretrain model, therefore, I will prepare the way to download it rather than package them toghther. Special thanks to these two repo for providing model.

  1. https://github.com/VisualComputingInstitute/triplet-reid
  2. https://github.com/chuanqi305/MobileNet-SSD
#opencv MobileNet model
wget https://raw.githubusercontent.com/chuanqi305/MobileNet-SSD/master/deploy.prototxt -P model
wget https://drive.google.com/u/0/uc?id=0B3gersZ2cHIxVFI1Rjd5aDgwOG8&export=download -O model/MobileNetSSD_deploy.caffemodel
#reid model
wget https://github.com/VisualComputingInstitute/triplet-reid/releases/download/250eb1/market1501_weights.zip -P model
unzip model/market1501_weights.zip -d model

Workflow

  1. Use opencv dnn module and use caffemodel to detection human in an image.
  2. Crop and resize all human(pedestrian) and resize to 256x128 images.
  3. Put image to resnet-50 human feature embedding extractor and get a 128-D feature array.
  4. Compare two human by using euclidean distance, the distance means the similarity of two image.

Example code

import cv2
import api

img1 = cv2.imread('test/test1.png')[:,:,::-1]
img1_location = api.human_locations(img1)
img_1_human = api.crop_human(img1, img1_location)
human_1_1 = img_1_human[0]
human_1_1_vector = api.human_vector(human_1_1)
# Do another people, and compare

Add Mobilenet backbone support

Thanks to the original repo, I trained a mobilenet backbone model which can accerlerate the speed of human embedding. You can check the time difference between mobilenet and resnet-50

Also, attached is the mobilenet backbone pretrained model that I trained. Here is the google drive link: https://drive.google.com/file/d/1JoJJ-rIrqXNrzrx12Ih4zFk09SYsKINC/view?usp=sharing

And the evaluation score of the model is:

mAP: 66.28% | top-1: 83.11% top-2: 88.42% | top-5: 93.79% | top-10: 95.90%

GitHub Logo

Please use mobilenet branch and download the pretrained model from the link and replace original resnet model

Acknowledgement and reference

  1. https://github.com/VisualComputingInstitute/triplet-reid
  2. https://github.com/chuanqi305/MobileNet-SSD
  3. https://github.com/opencv/opencv/tree/master/samples/dnn
@article{HermansBeyer2017Arxiv,
  title       = {{In Defense of the Triplet Loss for Person Re-Identification}},
  author      = {Hermans*, Alexander and Beyer*, Lucas and Leibe, Bastian},
  journal     = {arXiv preprint arXiv:1703.07737},
  year        = {2017}
}

pedestrian_recognition's People

Contributors

cftang0827 avatar tifu 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

Watchers

 avatar  avatar  avatar

pedestrian_recognition's Issues

Information on training

Hi I was just curious about how the model was trained. What dataset did you use and do you have the code in case we would like to retrain the model?

Thanks

Speed

Can I reduce the image size for more speed? Nice code thanks

Readme: Download file not found

Hi,
while trying to test your implementation I noticed the readme is out of date.

In Workflow section, point one has link which return 404.

Is the resource still available?

Thanks

crop_human extracts 0 height/width frame if x or y are negative

Hi!

Thanks for providing the weights & this model. It works amazingly well.

I noticed that sometimes the person detection emits bounding boxes with points minimally outside the image (e.g. [[(580, -2), (1271, 715)]]).

If you then call crop_human, it seems like the slice operator doesn't properly work with negative numbers:

Cropping image: Left Bottom (580, -2) /  Right Top (1271, 715)
Subframe: (0, 691, 3)

=> 0 width frame

I'd probably fix this by introducing max(0, detectionCoordinate) in human_locations during the scaling of the object location. Happy to provide a PR with the fix.

Cheers
Tino

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.