Coder Social home page Coder Social logo

keras_to_tf_ncs2's Introduction

Keras to Tensorflow to IR model (NCS2)

Goal

Convert a Keras or a Tensorflow model to IR files ready to be used with the Neural Compute Stick 2

Prerequisites

For that you want to have OpenVino installed and python 3.5 at least. For the python requirements, see the "Requirements" section.

File structure

How to use

Keras to Tensorflow conversion

If you have a Keras .h5 file, use keras_to_tf.py to create a Tensorflow .pb file.

    python keras_to_tf.py

that will take the Keras file situated in Keras_model/model.h5 and create a .pb file in TF_model/tf_model.pb.

Tensorflow to IR conversion

If you didn't had a .pb model before now you should have one. We'll use the model optimizer to convert the file.

    mo.py --data_type FP16 --framework tf --input_model TF_model/tf_model.pb --model_name IR_model --output_dir IR_model/ --input_shape [1,28,28,1] --input conv2d_1_input --output activation_6/Softmax

Runing the inference on the NCS2

Now you can run the inference on the NCS2. For that use the predict_mnist.py

    python predict_mnist.py

This file load the IR model, read and convert the data/6.jpg and feed it for classification.

If everything goes fine, you should see something like this:

    [ INFO ] Loading network files:
    IR_model/IR_model.xml
    IR_model/IR_model.bin
    [ INFO ] Preparing input blobs
    1 1 28 28
    (28, 28)
    (1, 28, 28)
    [ INFO ] Loading model to the plugin
    [ INFO ] Starting inference (1 iterations)
    [ INFO ] Average running time of one iteration: 1.8284320831298828 ms
    [ INFO ] Processing output blob
    [[0. 0. 0. 0. 0. 0. 1. 0. 0. 0.]]

The last line is the class vector. We have a 1 at index 6, so the image has been correctly classified.

Requirements

    pip install -r requirements.txt

keras_to_tf_ncs2's People

Contributors

dependabot[bot] avatar imgbotapp avatar mreliptik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

keras_to_tf_ncs2's Issues

TypeError: Keras symbolic inputs/outputs do not implement `op`. You may be trying to pass Keras symbolic inputs/outputs to a TF API that does not register dispatching, preventing Keras from automatically converting the API call to a lambda layer in the Functional Model.

Warning (from warnings module):
File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\keras\backend.py", line 414
warnings.warn('tf.keras.backend.set_learning_phase is deprecated and '
UserWarning: tf.keras.backend.set_learning_phase is deprecated and will be removed after 2020-10-11. To update it, simply pass a True/False value to the training argument of the __call__ method of your layer or model.
WARNING:tensorflow:No training configuration found in the save file, so the model was not compiled. Compile it manually.
Traceback (most recent call last):
File "E:\PYTHON\KERAS TO TF NCS\Keras_to_TF_NCS2-master\keras_to_tf.py", line 43, in
output_names=[out.op.name for out in model.outputs])
File "E:\PYTHON\KERAS TO TF NCS\Keras_to_TF_NCS2-master\keras_to_tf.py", line 43, in
output_names=[out.op.name for out in model.outputs])
File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\keras\engine\keras_tensor.py", line 233, in op
raise TypeError('Keras symbolic inputs/outputs do not '
TypeError: Keras symbolic inputs/outputs do not implement op. You may be trying to pass Keras symbolic inputs/outputs to a TF API that does not register dispatching, preventing Keras from automatically converting the API call to a lambda layer in the Functional Model.

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.