New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added basic Raspberry Pi example #2947
Merged
+524
−2
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
tensorflow_inception_graph.pb | ||
imagenet_comp_graph_label_strings.txt | ||
tensorflow_inception_stripped.pb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# TensorFlow Raspberry Pi Examples | ||
|
||
This folder contains examples of how to build applications for the Raspberry Pi using TensorFlow. | ||
|
||
## Building the Examples | ||
|
||
- Follow the Raspberry Pi section of the instructions at [tensorflow/contrib/makefile](https://github.com/tensorflow/tensorflow/tree/master/tensorflow/contrib/makefile) to compile a static library containing the core TensorFlow code. | ||
|
||
- Install libjpeg, so we can load image files: | ||
|
||
``` | ||
sudo apt-get install -y libjpeg-dev | ||
``` | ||
|
||
- To download the example model you'll need, run these commands: | ||
|
||
```bash | ||
curl https://storage.googleapis.com/download.tensorflow.org/models/inception_dec_2015_stripped.zip \ | ||
-o /tmp/inception_dec_2015_stripped.zip | ||
unzip /tmp/inception_dec_2015_stripped.zip \ | ||
-d tensorflow/contrib/pi_examples/label_image/data/ | ||
``` | ||
|
||
- From the root of the TensorFlow source tree, run `make -f tensorflow/contrib/pi_examples/label_image/Makefile` to build a basic example. | ||
|
||
## Usage | ||
|
||
Run `tensorflow/contrib/pi_examples/label_image/gen/bin/label_image` to try out image labeling with the default Grace Hopper image. You should several lines of output, with "Military Uniform" shown as the top result, something like this: | ||
|
||
```bash | ||
I tensorflow/contrib/pi_examples/label_image/label_image.cc:384] Running model succeeded! | ||
I tensorflow/contrib/pi_examples/label_image/label_image.cc:284] military uniform (866): 0.624293 | ||
I tensorflow/contrib/pi_examples/label_image/label_image.cc:284] suit (794): 0.0473981 | ||
I tensorflow/contrib/pi_examples/label_image/label_image.cc:284] academic gown (896): 0.0280926 | ||
I tensorflow/contrib/pi_examples/label_image/label_image.cc:284] bolo tie (940): 0.0156956 | ||
I tensorflow/contrib/pi_examples/label_image/label_image.cc:284] bearskin (849): 0.0143348 | ||
``` | ||
|
||
Once you've verified that is working, you can supply your own images with `--image=your_image.jpg`, or even with graphs you've trained yourself with the TensorFlow for Poets tutorial using `--graph=your_graph.pb --input=Mul:0 --output=softmax:0`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# This Makefile compiles the label_image example for the Raspberry Pi. | ||
# See tensorflow/contrib/pi_examples/README.md for full build instructions. | ||
|
||
# Find where we're running from, so we can store generated files here. | ||
SCRIPT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) | ||
|
||
# The location of the tensorflow/contrib/makefile directory. | ||
TFMAKEFILE_DIR := $(SCRIPT_DIR)/../../makefile | ||
|
||
# Where compiled objects are stored. | ||
GENDIR := $(SCRIPT_DIR)/gen/ | ||
OBJDIR := $(GENDIR)obj/ | ||
LIBDIR := $(GENDIR)lib/ | ||
BINDIR := $(GENDIR)bin/ | ||
|
||
# The expected locations of the TensorFlow library. | ||
TFLIBDIR := $(TFMAKEFILE_DIR)/gen/lib | ||
TFLIBS := $(TFLIBDIR)/libtensorflow-core.a | ||
|
||
# Where the downloads have been stored. | ||
DOWNLOADSDIR := $(TFMAKEFILE_DIR)/downloads | ||
|
||
# The location of the compiled protobuf headers generated by TensorFlow. | ||
PBTGENDIR := $(TFMAKEFILE_DIR)/gen/proto_text/ | ||
PROTOGENDIR := $(TFMAKEFILE_DIR)/gen/proto/ | ||
|
||
# The name of the output program we're compiling. | ||
EXECUTABLE_NAME := $(BINDIR)/label_image | ||
|
||
# Settings for the target compiler. | ||
CXX := gcc | ||
OPTFLAGS := -O0 | ||
CXXFLAGS := --std=c++11 $(OPTFLAGS) | ||
LDFLAGS := \ | ||
-L/usr/local/lib \ | ||
-L$(TFLIBDIR) \ | ||
-Wl,--no-whole-archive | ||
INCLUDES := \ | ||
-I/usr/local/include \ | ||
-I. \ | ||
-I$(DOWNLOADSDIR) \ | ||
-I$(DOWNLOADSDIR)/eigen-latest/ \ | ||
-I$(PROTOGENDIR) \ | ||
-I$(PBTGENDIR) | ||
LIBS := \ | ||
-lstdc++ \ | ||
-lprotobuf \ | ||
-Wl,--allow-multiple-definition \ | ||
-Wl,--whole-archive \ | ||
-ltensorflow-core \ | ||
-Wl,--no-whole-archive \ | ||
-ldl \ | ||
-lpthread \ | ||
-lm \ | ||
-ljpeg | ||
LIBFLAGS := | ||
|
||
EXECUTABLE_SRCS := tensorflow/contrib/pi_examples/label_image/label_image.cc | ||
|
||
# File names of the intermediate files target compilation generates. | ||
EXECUTABLE_OBJS := $(addprefix $(OBJDIR), $(EXECUTABLE_SRCS:.cc=.o)) | ||
|
||
.PHONY: clean | ||
|
||
# The target that's compiled if there's no command-line arguments. | ||
all: $(EXECUTABLE_NAME) | ||
|
||
# Rules for target compilation. | ||
|
||
$(EXECUTABLE_NAME): $(EXECUTABLE_OBJS) $(TFLIBS) | ||
@mkdir -p $(dir $@) | ||
$(CXX) $(CXXFLAGS) $(INCLUDES) \ | ||
-o $(EXECUTABLE_NAME) $(EXECUTABLE_OBJS) \ | ||
$(LIBFLAGS) $(LIB_PATH) $(LDFLAGS) $(LIBS) | ||
|
||
# Matches on C++ source files. | ||
$(OBJDIR)%.o: %.cc | ||
@mkdir -p $(dir $@) | ||
$(CXX) $(CXXFLAGS) $(INCLUDES) -c $< -o $@ | ||
|
||
# Gets rid of all generated files. | ||
clean: | ||
rm -rf $(GENDIR) |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe:
"This folder contains an example of a Raspberry Pi application that uses TensorFlow", as there's only one example.