Giter Site home page Giter Site logo

shanexia1818 / keras-multiple-process-prediction Goto Github PK

View Code? Open in Web Editor NEW

This project forked from yuanyuanli85/keras-multiple-process-prediction

0.0 1.0 0.0 6 KB

A Simply Example to show how to use Keras model in multiple processes to do the prediction

Python 100.00%

keras-multiple-process-prediction's Introduction

Simple Example to run Keras models in multiple processes

This git repo contains an example to illustrate how to run Keras models prediction in multiple processes with multiple gpus. Each process owns one gpu. I wanted to run prediction by using multiple gpus, but did not find a clear solution after searching online. So, I created this example to show how to do that. Hope this git repo can help others who met the same problem.

This software works as a producer-consumer model. The scheduler scans the image path and put all of them into a Queue; while each worker as a separate process process the images in the Queue. If all of images are proceeded, the worker process will terminate.

Pay attention to the implementation Vgg16Worker::Run()

def run(self):
    #set environment
    os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID"
    os.environ["CUDA_VISIBLE_DEVICES"] = str(self._gpuid)
    #load models
    import vgg16
    #download the vgg16 weights from
    xnet = vgg16.Vgg16('vgg16_weights_tf_dim_ordering_tf_kernels.h5')

    print 'vggnet init done', self._gpuid

    while True:
        xfile = self._queue.get()
        if xfile == None:
            self._queue.put(None)
            break
        label = self.predict(xnet, xfile)
        print 'woker', self._gpuid, ' xfile ', xfile, " predicted as label", label

How to run the sample

Dependency:

  • Keras 2.0
  • Tensorflow
  • OpenCV

Download VGG16 Keras Model from: https://github.com/fchollet/deep-learning-models/releases/download/v0.1/vgg16_weights_tf_dim_ordering_tf_kernels.h5

Command: usage: main.py [-h] [--imgpath IMGPATH] [--gpuids GPUIDS]

optional arguments: -h, --help show this help message and exit --imgpath IMGPATH path to your images to be proceed --gpuids GPUIDS gpu ids to run

keras-multiple-process-prediction's People

Contributors

keineahnung2345 avatar yli150 avatar yuanyuanli85 avatar

Watchers

 avatar

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.