Runing Keras(Background: TensorFlow) with Intel Movidius Neural Compute Stick
Thank Mustafa Aldemir
and Intel Corporation Turkey
very much for this gift !
Official Web Page: developer.movidius.com
git clone http://github.com/Movidius/ncsdk && cd ncsdk && make install
Run make examples
command inside ncsdk folder.
Look up: github.com/movidius/ncappzoo
File: keras2graph.py
Converts Keras model and weights to Intel Movidius technology internal compiled format.
keras2graph
process turn used TensorFlow backend Keras models to NCS graph.
Keras Model -> TensorFlow Session -> TensorFlow Meta File -> NCS Graph
python3 keras2graph.py <Keras_Model> <Model_input_layer_name> <Model_output_layer_name> <Keras_Model_Weights> <Output_Graph>
This command creates and saves graph file as <Output_Graph>
.
python3 keras2graph.py Keras_Model/model.json input_1 activation_7/Softmax Keras_Model/weights.h5 ./graph
keras_to_graph(model_path, model_in, model_out, weights_path, graph_path, take_tf_files = False)
For converting Keras Model to Movidius NCS graph.
model_path
: Model location. Json file. Data Type: Stringmodel_in
: Name of model's input layer. Data Type: Stringmodel_out
: Name of model's output layer. Data Type: Stringgraph_path
: Location of output Intel Movidius technology internal compiled format graph. Data Type: Stringtake_tf_files
: If you don't want to delete created TensorFlow model files(meta file inside), selectFalse
. Data Type: Bool
get_keras_model(model_path, weights_path)
For getting Keras model.
model_path
: Keras model Json file. Data Type: Stringweights_path
: Weights of Keras model. h5 file. Data Type: String
model
: Keras model object.
keras_to_tf(tf_model_path)
For converting Keras model to TensorFlow session and saving TensorFlow graph to meta file.
Important Note: Use this function after get_keras_model
function.
tf_model_path
: Saving location of output meta file. Data Type: String
tf_to_graph(tf_model_path, model_in, model_out, graph_path):
For converting TensorFlow graph to Intel Movidius technology internal compiled format.
tf_model_path
: Location of TensorFlow meta file. Data Type: Stringmodel_in
: Name of model's input layer. Data Type: Stringmodel_out
: Name of model's output layer. Data Type: Stringgraph_path
: Location of output Intel Movidius technology internal compiled format graph. Data Type: String
File: ncs_process.py
ready_ai_ncs(graph_path, device_index=0)
For getting ready Movidius NCS with model to use with one command.
graph_path
: Graph file path. Data type: Stringdevice_index
: Which device you want use. Data type: Int , Default value: 0
ncs_model
: Model object. This object ready for running graph in NCS (ncs_model
object used withncs_predict()
function)device
: Using device object.
release_ai_ncs(ncs_model, device)
For release model(in the Movidius NCS) and close Movidius device.
ncs_model
: Model object. (Returned fromready_ai_ncs
)device
: Using device object.
ncs_predict(ncs_model, inputs)
For running Intel Movidius technology internal compiled format graph in Intel Movidius NCS.
ncs_model
: Intel Movidius technology internal compiled format graph object.inputs
: Input matrics. Data type: Numpy Array
outputs
: Output of graph. Data type: Numpy Array
- Install necessary modules with
sudo pip3 install -r requirements.txt
command.