Giter Club home page Giter Club logo

keras_mnist's Introduction

Intel® Movidius™ NCS MNIST example for NCSDK2

Requirements

  • NCSDK2 installed to compile model and use its Python API.
  • Keras installed for training the model.
pip3 install keras

Quick start

  • Optionally, copy this folder into your NCSDK2 directory along with other TensorFlow examples. ncsdk/examples/tensorflow/keras_mnist
  • Plug NCS to a USB port on the host machine.
  • Run command - make all
  • Run command - make run

Makefile

Provided Makefile describes various targets that help with the above mentioned tasks.

make all

Runs Keras model training(only for the first time), ncprofile, nccheck, nccompile.

make train

Train and save Keras MNIST model if Keras model files are not found.

make profile

Runs the provided network on the NCS and generates per layer statistics that are helpful for understanding the performance of the network on the Neural Compute Stick.

make compile

Uses the network description and the trained weights files to generate a Movidius internal 'graph' format file. This file is later used for loading the network on to the Neural Compute Stick and executing the network.

make run

Runs the provided predict-mnist-ncsdk2.py file which sends a single image to the Neural Compute Stick and receives and displays the inference results.

make run_cam

Runs the provided predict-mnist-ncsdk2-cam.py file which is similar to previous demo but take live webcam image as input.

make check

Runs the network on Caffe on CPU and runs the network on the Neural Compute Stick. Check then compares the two results to make sure they are consistent with each other.

make clean

Removes all the temporary files and trained model files that are created by the Makefile


After training the Keras MNIST model, 3 files will be generated, while the conversion script convert-mnist.py only use the first 2 files to generate TensorFlow model files into TF_Model directory.

model.json Only contain model graph (Keras Format).

weights.h5 Only contain model weights (Keras Format).

model.h5 Both contain model graph and weights (Keras Format).

Reference

keras_mnist's People

Contributors

tony607 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

keras_mnist's Issues

error converting keras trained model into movidius compatible graph

for converting i used:
mvNCCompile tf_model.meta -s 12 -in=conv2d_1_input -on=dense_2/Softmax -is 28 28 -o mgraph.graph
give error :
mvNCCompile v02.00, Copyright @ Movidius Ltd 2016

/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/ops.py:766: DeprecationWarning: builtin type EagerTensor has no module attribute
EagerTensor = c_api.TFE_Py_InitEagerTensor(_EagerTensorBase)
/usr/local/lib/python3.5/dist-packages/tensorflow/python/util/tf_inspect.py:45: DeprecationWarning: inspect.getargspec() is deprecated, use inspect.signature() instead
if d.decorator_argspec is not None), _inspect.getargspec(target))
/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/tensor_util.py:509: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
return np.fromstring(tensor.tensor_content, dtype=dtype).reshape(shape)
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 1323, in _do_call
return fn(*args)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 1302, in _run_fn
status, run_metadata)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/errors_impl.py", line 473, in exit
c_api.TF_GetCode(self.status.status))
tensorflow.python.framework.errors_impl.InvalidArgumentError: You must feed a value for placeholder tensor 'conv2d_1_input' with dtype float and shape [?,28,28,1]
[[Node: conv2d_1_input = Placeholderdtype=DT_FLOAT, shape=[?,28,28,1], _device="/job:localhost/replica:0/task:0/device:CPU:0"]]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/bin/mvNCCompile", line 118, in
create_graph(args.network, args.inputnode, args.outputnode, args.outfile, args.nshaves, args.inputsize, args.weights)
File "/usr/local/bin/mvNCCompile", line 104, in create_graph
net = parse_tensor(args, myriad_config)
File "/usr/local/bin/ncsdk/Controllers/TensorFlowParser.py", line 1059, in parse_tensor
desired_shape = node.inputs[1].eval()
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/ops.py", line 570, in eval
return _eval_using_default_session(self, feed_dict, self.graph, session)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/ops.py", line 4455, in _eval_using_default_session
return session.run(tensors, feed_dict)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 889, in run
run_metadata_ptr)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 1120, in _run
feed_dict_tensor, options, run_metadata)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 1317, in _do_run
options, run_metadata)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 1336, in _do_call
raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.InvalidArgumentError: You must feed a value for placeholder tensor 'conv2d_1_input' with dtype float and shape [?,28,28,1]
[[Node: conv2d_1_input = Placeholderdtype=DT_FLOAT, shape=[?,28,28,1], _device="/job:localhost/replica:0/task:0/device:CPU:0"]]

Caused by op 'conv2d_1_input', defined at:
File "/usr/local/bin/mvNCCompile", line 118, in
create_graph(args.network, args.inputnode, args.outputnode, args.outfile, args.nshaves, args.inputsize, args.weights)
File "/usr/local/bin/mvNCCompile", line 104, in create_graph
net = parse_tensor(args, myriad_config)
File "/usr/local/bin/ncsdk/Controllers/TensorFlowParser.py", line 213, in parse_tensor
saver = tf.train.import_meta_graph(path, clear_devices=True)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/training/saver.py", line 1810, in import_meta_graph
**kwargs)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/meta_graph.py", line 660, in import_scoped_meta_graph
producer_op_list=producer_op_list)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/importer.py", line 313, in import_graph_def
op_def=op_def)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/ops.py", line 2956, in create_op
op_def=op_def)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/ops.py", line 1470, in init
self._traceback = self._graph._extract_stack() # pylint: disable=protected-access

InvalidArgumentError (see above for traceback): You must feed a value for placeholder tensor 'conv2d_1_input' with dtype float and shape [?,28,28,1]
[[Node: conv2d_1_input = Placeholderdtype=DT_FLOAT, shape=[?,28,28,1], _device="/job:localhost/replica:0/task:0/device:CPU:0"]]

ValueError: axes don't match array

Hi,
This code works fine for a convolutional neural network but when I try it with the deep neural network below:

_**************************
import pandas as pd
from keras import layers
from keras.models import Sequential
from keras.layers import Dense
from keras.callbacks import EarlyStopping

train_df = pd.read_csv('./data/hourly_wages_data.csv')
train_X = train_df.drop(['wage_per_hour'], axis=1)
train_y = train_df[['wage_per_hour']]

n_cols = train_X.shape[1]

model= Sequential()
model.add(layers.Dense(200, activation='relu', input_shape=(n_cols,)))
model.add(layers.Dense(200, activation='relu'))
model.add(layers.Dense(200, activation='relu'))
model.add(layers.Dense(1, activation = 'softmax'))

model.compile(optimizer='adam', metrics=['accuracy'],loss='mean_squared_error')

model.fit(train_X, train_y, validation_split=0.2, epochs=30, batch_size=70)_


When I use the mvNCCheck, I get this error :

_/usr/local/bin/ncsdk/Controllers/Parsers/TensorFlowParser/Convolution.py:47: SyntaxWarning: assertion is always true, perhaps remove parentheses?
assert(False, "Layer type not supported by Convolution: " + obj.type)
mvNCCheck v02.00, Copyright @ Intel Corporation 2017

****** Info: No Weights provided. inferred path: TF_Model/tf_model.data-00000-of-00001******
TF_Model/tf_model.meta
2019-05-23 16:07:34.948186: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
No Bias
No Bias
No Bias
No Bias
Fusing DeptwiseConv + Pointwise Convolution into plain Convolution
Fusing Add and Batch after Convolution
Traceback (most recent call last):
File "/usr/local/bin/mvNCCheck", line 239, in
quit_code = check_net(args.network, args.image, args.inputnode, args.outputnode, args.nshaves, args.inputsize, args.weights, args)
File "/usr/local/bin/mvNCCheck", line 206, in check_net
load_ret = load_network(args, parser, myriad_config)
File "/usr/local/bin/ncsdk/Controllers/Scheduler.py", line 83, in load_network
input_data, expected_result = p.calculateReference(arguments)
File "/usr/local/bin/ncsdk/Controllers/Parsers/TensorFlow.py", line 545, in calculateReference
nhwc_to_nchw_transpozition)
File "/home/tam/.local/lib/python3.5/site-packages/numpy/core/fromnumeric.py", line 639, in transpose
return _wrapfunc(a, 'transpose', axes)
File "/home/tam/.local/lib/python3.5/site-packages/numpy/core/fromnumeric.py", line 56, in wrapfunc
return getattr(obj, method)(*args, **kwds)
ValueError: axes don't match array

Is it normal? Could you help me please resolving this issue.
Thank you in advance

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.