Home | History | Annotate | only in /external/tensorflow/tensorflow/contrib/pi_examples
Up to higher level directory
NameDateSize
camera/22-Oct-2020
label_image/22-Oct-2020
README.md22-Oct-20203.4K

README.md

      1 # TensorFlow Raspberry Pi Examples
      2 
      3 This folder contains examples of how to build applications for the Raspberry Pi using TensorFlow.
      4 
      5 ## Building the Examples
      6 
      7  - 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.
      8 
      9  - Install libjpeg, so we can load image files:
     10 
     11 ```
     12 sudo apt-get install -y libjpeg-dev
     13 ```
     14 
     15  - To download the example model you'll need, run these commands:
     16 
     17 ```bash
     18 curl https://storage.googleapis.com/download.tensorflow.org/models/inception_dec_2015_stripped.zip \
     19 -o /tmp/inception_dec_2015_stripped.zip
     20 unzip /tmp/inception_dec_2015_stripped.zip \
     21 -d tensorflow/contrib/pi_examples/label_image/data/
     22 ```
     23 
     24  - From the root of the TensorFlow source tree, run `make -f tensorflow/contrib/pi_examples/label_image/Makefile` to build a basic example.
     25 
     26 ## Usage
     27 
     28 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:
     29 
     30 ```bash
     31 I tensorflow/contrib/pi_examples/label_image/label_image.cc:384] Running model succeeded!
     32 I tensorflow/contrib/pi_examples/label_image/label_image.cc:284] military uniform (866): 0.624293
     33 I tensorflow/contrib/pi_examples/label_image/label_image.cc:284] suit (794): 0.0473981
     34 I tensorflow/contrib/pi_examples/label_image/label_image.cc:284] academic gown (896): 0.0280926
     35 I tensorflow/contrib/pi_examples/label_image/label_image.cc:284] bolo tie (940): 0.0156956
     36 I tensorflow/contrib/pi_examples/label_image/label_image.cc:284] bearskin (849): 0.0143348
     37 ```
     38 
     39 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=final_result:0`.
     40 
     41 ## Camera Example
     42 
     43 Once you have the simple example running, you can try out a more complex version that
     44 reads frames from a camera attached to the Pi. You'll need to install and set up your
     45 camera module first. The example uses Video4Linux, so you'll need to install that first.
     46 Here's some commands I found necessary to get that set up, and I found more information
     47 at this blog post: http://www.richardmudhar.com/blog/2015/02/raspberry-pi-camera-and-motion-out-of-the-box-sparrowcam/
     48 
     49 ```
     50 sudo bash -c "echo 'bcm2835-v4l2' >> /etc/modules"
     51 sudo apt-get install libv4l-dev
     52 ```
     53 
     54 Once that's working, run the following commands to build and run the camera example:
     55 
     56 ```bash
     57 make -f tensorflow/contrib/pi_examples/camera/Makefile
     58 tensorflow/contrib/pi_examples/camera/gen/bin/camera
     59 ```
     60 
     61 You should see it looping over camera frames as they come in, and printing the top labels
     62 to the command line. This is a great starting point for all sorts of fun image recognition
     63 applications, especially when you combine it with a custom model you've built using
     64 something like the TensorFlow for Poets tutorial.
     65 
     66 The example is designed to work with the Flite speech synthesis tool, so that your Pi
     67 can speak any labels that have a high enough score. To enable this, just install the
     68 Flite package and then pipe the output of the binary you've built, like this:
     69 
     70 ```
     71 sudo apt-get install flite
     72 tensorflow/contrib/pi_examples/camera/gen/bin/camera | xargs -n 1 flite -t
     73 ```
     74