Skip to content

Commit

Permalink
vesrion 1.00.00.00 of app zoo
Browse files Browse the repository at this point in the history
  • Loading branch information
nealvis committed Oct 10, 2017
1 parent d47fdbc commit 1991da5
Show file tree
Hide file tree
Showing 177 changed files with 50,704 additions and 31 deletions.
20 changes: 20 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Set the default behavior, in case people don't have core.autocrlf set.
* text=auto

*.sh text eol=lf
sshd_config text eol=lf

# Explicitly declare text files you want to always be normalized and converted
# to native line endings on checkout.
*.c text
*.h text
*.cpp text
*.hpp text
*.py text

# Declare files that will always have CRLF line endings on checkout.
*.sln text eol=crlf

# Denote all files that are truly binary and should not be modified.
*.png binary
*.jpg binary
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# ignore build directories and any files in build directories
build/

# ignore any qt-creator user files for cmake projects. these are files
# specific to a user and specific to qt-creator
CMakeLists.txt.user


108 changes: 108 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
## Contributing to the Movidius™ Neural Compute App Zoo (NC App Zoo)

We are glad you want to contribute with a model and/or software for the NC App Zoo. This is the a great way to help the developer community. We encourage submissions from any and all developers interested in the Movidius™ Neural Compute Stick (NCS).


## Submitting a pull request

To contribute with a new app or neural network for the NC App Zoo, fork the repository and add (commit) any of the following new subdirectories containing your content (your content could contain any or all of the following):
- apps/(new app name)
- caffe/(new caffe network name)
- tensorflow/(new tensorflow network name)

Your application code goes under **apps**, any neural network that you have working with the NCS will go under **caffe**, or **tensorflow** as appropriate for the framework used.

After you have committed changes to your fork of the App Zoo (always commit using the --signoff option as described in the Contribution Licensing section below), create a pull request for the new directories to be pulled into this repo (the NC App Zoo repository.)

## Content guidelines
The guidelines for what each directory should contain are as follows.

### The **apps** subdirectories
The following **should** be included apps subdirectories:
- README.md : Markdown file that explains everything needed to build and run your application.
- Makefile : Builds any source code and downloads or copies (from other repo subdirectories) any required files. If your app needs content from other areas in the repo, like a network graph file, your Makefile should invoke the other Makefile to produce the content needed. You can use the apps/stream_infer/Makefile as the pattern to follow.
- AUTHORS : text file with names, email addresses and organizations for all authors of contribution.

The following should **not** typically be stored in the apps subdirectories:
- NCS graph files. These can be created from your Makefile
- Neural network models. These should originate from the caffe or tensorflow directories.
- Trained neural networks (weights.) Typically these should be downloaded by a Makefile in the caffe, or tensorflow subdirectories
- Training data. This should be downloaded by a Makefile a subdirectory of the data directory
- Images files. These should be downloaded to (if many) or stored in (if not too many) a subdirectory of the data directory

### The **caffe** subdirectories
The following **should** be included in the caffe subdirectories. Use caffe/GoogLeNet as an example to follow.
- README.md : Markdown file that explains how a developer can use the content in the subdirectory.
- Makefile : Should have targets to download any large files such as the trained network files, compile NCS graph files, build and run a small code example.
- Small example program (optional): Small C, C++, or Python program that demonstrates how to use the network with the NCS
- Network model files (.prototxt) file. Its typically downloaded via the makefile if you don't own the trained network
- Network mean information. Its typically downloaded via the make file if you don't own the trained network
- AUTHORS : text file with names, email addresses and organizations for all authors of contribution.

The following should **not** typically be stored in the caffe subdirectory
- NCS graph files. These should be created via the Makefile which should invoke the SDK compiler to create the graph file.
- Trained neural network files. These should be downloaed from their internet home via the Makefile
- Training data. If needed training data can be downloaded via the Makefile in a subdirectory of the data directory.
- Images files. These should be downloaded to (if many) or stored in (if not too many) a subdirectory of the data directory

### The **tensorflow** subdirectories
The following **should** be included in the tensorflow subdirectories. Use tensorflow/inception_v1 as an example to follow.
- README.md : Markdown file that explains how a developer can use the content in the subdirectory.
- Makefile : Should have targets to download any large files such as the trained network files, compile NCS graph files, build and run a small code example.
- Small example program (optional): Small C, C++, or Python program that demonstrates how to use the network with the NCS
- Network mean information. Its typically downloaded via the make file if you don't own the trained network
- AUTHORS : text file with names, email addresses and organizations for all authors of contribution.

The following should **not** typically be stored in the tensorflow subdirectory
- NCS graph files. These should be created via the Makefile which should invoke the SDK compiler to create the graph file.
- Trained neural network files. These should be downloaed from their internet home via the Makefile
- Training data. If needed training data can be downloaded via the Makefile in a subdirectory of the data directory.
- Images files. These should be downloaded to (if many) or stored in (if not too many) a subdirectory of the data directory


## Contribution Licensing
All contributions must be licensed under the MIT license [https://opensource.org/licenses/MIT](https://opensource.org/licenses/MIT) unless otherwise stated in a lower level directory for exceptional cases. The [LICENSE](LICENSE) file in the repository top level directory provides the MIT license details.

Also, for your contribution to be accepted, each commit must be "Signed-off". This is done by commiting using this command: `git commit --signoff`

By signing off your commits, you agree to the following agreement, also known as [Developer Certificate of Origin](http://developercertificate.org/): it assures everyone that the code you're submitting is yours or that you have rights to submit it.

```
Developer Certificate of Origin
Version 1.1
Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
660 York Street, Suite 102,
San Francisco, CA 94110 USA
Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.
Developer's Certificate of Origin 1.1
By making a contribution to this project, I certify that:
(a) The contribution was created in whole or in part by me and I
have the right to submit it under the open source license
indicated in the file; or
(b) The contribution is based upon previous work that, to the best
of my knowledge, is covered under an appropriate open source
license and I have the right under that license to submit that
work with modifications, whether created in whole or in part
by me, under the same open source license (unless I am
permitted to submit under a different license), as indicated
in the file; or
(c) The contribution was provided directly to me by some other
person who certified (a), (b) or (c) and I have not modified
it.
(d) I understand and agree that this project and the contribution
are public and that a record of the contribution (including all
personal information I submit with it, including my sign-off) is
maintained indefinitely and may be redistributed consistent with
this project or the open source license(s) involved.
```

4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
The MIT License (MIT)
Copyright � 2017 Intel Corporation
Copyright © Application and model owners

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Expand All @@ -18,4 +18,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 changes: 25 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

ifneq ($(findstring movidius, $(PYTHONPATH)), movidius)
export PYTHONPATH:=/opt/movidius/caffe/python:/opt/movidius/mvnc/python:$(PYTHONPATH)
endif

TOPTARGETS := all clean check profile compile run

SUBDIRS := $(wildcard */.)

$(TOPTARGETS): $(SUBDIRS)
$(SUBDIRS):
$(MAKE) -C $@ $(MAKECMDGOALS)

.PHONY: $(TOPTARGETS) $(SUBDIRS)

.PHONY: help
help:
@echo "Possible Make targets"
@echo " make help - shows this message"
@echo " make all - Makes all targets"
@echo " make clean - Removes all temp files from all directories"
@echo " make check - Runs check on all caffe/tensorflow models"
@echo " make profile - Runs profile on all caffe/tensorflow models"
@echo " make compile - Runs compile on all caffe/tensorflow models"
@echo " make run - Runs all caffe/tensorflow/apps"
13 changes: 13 additions & 0 deletions OWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Directory, Directory Maintainer, Contact email

apps/benchmarkncs, Intel Corporation, ramana.rachakonda@intel.com
apps/MultiStick_GoogLeNet, Intel Corporation, ramana.rachakonda@intel.com
apps/stream_infer, Intel Corporation, neal.p.smith@intel.com

caffe/AlexNet, Intel Corporation, neal.p.smith@intel.com
caffe/GoogleNet, Intel Corporation, neal.p.smith@intel.com
caffe/SqueezeNet, Intel Corporation, neal.p.smith@intel.com

tensorflow/inception_v1, Intel Corporation, neal.p.smith@intel.com
tensorflow/inception_v2, Intel Corporation, neal.p.smith@intel.com

25 changes: 23 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,25 @@
# Neural Compute Application Zoo (NC App Zoo)

#Example code for the Movidius Neural Compute Stick.
Welcome to the Movidius™ Neural Compute App Zoo (NC App Zoo.) This repository is a place for any interested developers to share their projects (code and Neural Network content) that make use of the Movidius™ Neural Compute Stick (NCS) and associated [Movidius™ Neural Compute Software Development Kit](http://www.github.com/movidius/ncsdk)

The NC App Zoo is a community repository with many content owners and maintainers. All NC App Zoo content is being made available here in a central location for others to download, experiment with, modify, build upon, and learn from.

# NC App Zoo Repository Layout
The NC App Zoo contains the following top level directories
- **apps** : Applications built to use the NCS
- **caffe** : Scripts to download caffe models and compile graphs for use with the NCS
- **data** : Data and scripts to download data for use with models and applciations that use the NCS
- **tensorflow** : Scripts to download TensorFlow mdoels and compile graphs for use with the NCS

The top level directories above have subdirectories which hold project content. Each of these project subdirectories has one or more owner that assumes responsibility for it. The [OWNERS](OWNERS) file contains the mapping of subdirectory to owner.

# Contributing to the Neural Compute Application Zoo
The more contributions to the NC App Zoo, the more successfull the community will be! We always encourage everyone with NCS related content to share by contributing their appclications and model related work to the NC App Zoo. It's easy to do, and if contributing new content you will be the owner and maintainer of the content.
See the [CONTRIBUTING.md](CONTRIBUTING.md) file for instructions and guidelines for contributing.


# Licensing
All content in the NC App Zoo is licensed via the [MIT license](https://opensource.org/licenses/MIT) unless specifically stated otherwise in lower level projects. Individual model and code owners maintain the copyrights for their content but provide it to the community in accordance with the MIT License

See the [LICENSE](LICENSE) file in the top level directory for all licensing details including reuse and redistribution of content in the NC App Zoo respository.

See the LICENSE file for details of reuse and redistribution of repo files.
23 changes: 23 additions & 0 deletions apps/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

ifneq ($(findstring movidius, $(PYTHONPATH)), movidius)
export PYTHONPATH:=/opt/movidius/caffe/python:/opt/movidius/mvnc/python:$(PYTHONPATH)
endif

TOPTARGETS := all clean

SUBDIRS := $(wildcard */.)

$(TOPTARGETS): $(SUBDIRS)
$(SUBDIRS):
$(MAKE) -C $@ $(MAKECMDGOALS)

.PHONY: $(TOPTARGETS) $(SUBDIRS)

.PHONY: help
help:
@echo "Possible make targets: ";
@echo " make help - shows this message";
@echo " make all - does make all in each sub directory";
@echo " make clean - does make clean in each subdirectory";

check profile compile run:
130 changes: 130 additions & 0 deletions apps/MultiStick_GoogLeNet/GoogLeNetOnCaffe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
#! /usr/bin/env python3

# *******************************************************
# Copyright(c) 2017 Intel Corporation.
# License: MIT See LICENSE file in root directory.
# *******************************************************

# ****************************************************************************************
caffe_root = '/opt/movidius/caffe/'
imgroot = "../../data/images/"
# ****************************************************************************************

import sys
sys.path.insert(0, caffe_root + 'python')
import numpy as np
import os
from os import *
from os.path import *
from multiprocessing import Process, Queue

onlyfiles = [f for f in os.listdir(imgroot) if isfile(join(imgroot, f))]
onlyfiles = onlyfiles[:100]

def caffeRun(dispQ):
import caffe
imgarr = []
caffe.set_mode_cpu()
system("(cd ../../caffe/GoogLeNet; make caffemodel; make prereqs)")
model_def = caffe_root + 'models/bvlc_googlenet/deploy.prototxt'
model_weights = '../../caffe/GoogLeNet/bvlc_googlenet.caffemodel'

net = caffe.Net(model_def, model_weights, caffe.TEST)

# load the mean ImageNet image (as distributed with Caffe) for subtraction
mu = np.load('../../data/ilsvrc12/ilsvrc_2012_mean.npy')
mu = mu.mean(1).mean(1) # average over pixels to obtain the mean (BGR) pixel values

# create transformer for the input called 'data'
transformer = caffe.io.Transformer({'data': net.blobs['data'].data.shape})

transformer.set_transpose('data', (2,0,1)) # move image channels to outermost dimension
transformer.set_mean('data', mu) # subtract the dataset-mean value in each channel
transformer.set_raw_scale('data', 255) # rescale from [0, 1] to [0, 255]
transformer.set_channel_swap('data', (2,1,0)) # swap channels from RGB to BGR

print("Scanning files")
image_ext_list = [".jpg", ".png", ".JPEG", ".jpeg", ".PNG", ".JPG"]
for file in onlyfiles:
fimg = imgroot + file
if any([x in image_ext_list for x in fimg]):
print(fimg + " is not an image file")
continue
img = caffe.io.load_image(fimg)
transformed_image = transformer.preprocess('data', img)
imgarr.append(transformed_image)
print("Done! Starting computation")
for i in range(len(imgarr)):
dispQ.put((i, ""))
img = imgarr[i]
net.blobs['data'].data[...] = img
output = net.forward()
output_prob = output['prob'][0]
print('predicted class is:', output_prob.argmax())
labels_file = "../../data/ilsvrc12/synset_words.txt"
labels = np.loadtxt(labels_file, str, delimiter='\t')
output_label = labels[output_prob.argmax()]
output_label = ' '.join(output_label.split(',')[0].split(' ')[1:])
dispQ.put((i, output_label))
dispQ.put((-1, None))

def cvPreprocess():
import cv2
imgarr_orig = []
image_ext_list = [".jpg", ".png", ".JPEG", ".jpeg", ".PNG", ".JPG"]
for file in onlyfiles:
fimg = imgroot + file
if any([x in image_ext_list for x in fimg]):
print(fimg + " is not an image file")
continue
img1 = cv2.imread(fimg)
if img1 is None:
print ("ERROR opening ", fimg)
continue
img1 = cv2.resize(img1, (896, 896))
imgarr_orig.append(img1)
return imgarr_orig

def displaythread(dispQ):
import cv2
imgarr_orig = cvPreprocess()
print("Got Display Images!")
print("Starting Display Thread")
last = (None, None)
while 1:
n = -1
label = None
try:
(n, label) = dispQ.get(True, 1)
if n < 0:
break
last = (n, label)
except:
(n, label) = last
if n == None:
continue
img = imgarr_orig[n]
label = str(n)+" "+label
cv2.putText(img, label, (100,850), cv2.FONT_HERSHEY_SIMPLEX, 2, (0,0,255), 6)
# show the frame and record if the user presses a key
cv2.imshow("Image", img)
key = cv2.waitKey(1500) & 0xFF
# if the `q` key is pressed, break from the loop
if key == ord("q"):
break

# cleanup the camera and close any open windows
cv2.destroyAllWindows()

if __name__=="__main__":
dispQ = Queue()

dthread = Process(target=displaythread, args=(dispQ,))
cthread = Process(target=caffeRun, args=(dispQ,))

cthread.start()
dthread.start()

cthread.join()
dthread.join()

0 comments on commit 1991da5

Please sign in to comment.