Giter Site home page Giter Site logo

keras-lsc-cnn's Introduction

Keras-LSC-CNN

This repository contains an unofficial Keras Implementation of LSC-CNN, a crowd counting model as proposed in the paper Locate, Size and Count: Accurately Resolving People in Dense Crowds via Detection. Currently, the implementation only supports parsing weights from the pytroch pretrained model for inference purposes.

Thanks to Skand for the help during the process of porting the model to Keras.

Some functions were taken from the official pytorch implementation repository for performing NMS.

Provided in this repository are:

  1. network.py, containing the keras definition of the LSC-CNN model, and some functions for performing inference.
  2. convert_lsccnn_to_keras.py, containing the code that reads the weight file of the pretrained torch models and outputs a keras model with weights from the pretrained pytorch model loaded into it.
  3. main.py, as an example showing how to create the converted keras model along with how to use it for inference.

Usage

1. Converting model to keras

To convert a pytorch model to keras, first you will need to:

And then, you can either:

  • use the function convert_torch_model_to_keras, supplying the path to the .pth file as such:
from convert_lsccnn_to_keras import convert_torch_model_to_keras
# ...
# fill in with the path to pth model
model = convert_torch_model_to_keras('/path/to/pth/file')
# this will return a keras Model. You can use it straight for inference or just save it for later
# ...

Or

  • Use convert_lsccnn_to_keras.py as a command line program like such and retrieve the .h5 file
python3 convert_lsccnn_to_keras.py --pthpath /path/to/pth/file --savedir /where/to/save/model

2. Doing inference with the model

network.py contains the functions you will need for inference. Function pred_for_one_image can be used to do prediction.

from network import pred_for_one_image
# ...
model = # the lsccnn model
image = # .. make sure the image is in shape (height, width, channels) and is in RGB format
loc, h, w = pred_for_one_image(model,image)
# loc is a binary array, True if a certain pixel is decided as a center for a detected head
# h and w is the respective box height and widths for every locations

TODO :

  • Implement NMS as a keras function if possible
  • vectorize a lot of operations on NMS
  • create a prediction function for batch images

keras-lsc-cnn's People

Contributors

anant15 avatar usamahjundia avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

anant15

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.