Build your AWS Lambda Machine Learning Function with Docker

I've recently made a tutorial on using Docker for machine learning purposes, and I thought also to publish it in here: http://hi.cs.stonybrook.edu/teaching/docker4ml

It includes videos, slides and code, with hands-on demonstrations in class.

A GitHub repo holds the code: https://github.com/royshil/Docker4MLTutorial

I made several scripts to make it easy to upload python code that performs an ML inference ("prediction") operation on AWS Lambda.

Enjoy!
Roy.

Share

Cross Compile TensorFlow C++ app for the Jetson TK1

Last time I've posted about cross compiling TF for the TK1. That however was a canned sample example from TF, based on the bazel build system.
Let's say we want to make our own TF C++ app and just link vs. TF for inference on the TK1.
Now that's a huge mess.

First we need to cross-compile TF with everything built in.
Then we need protobuf cross-compiled for the TK1.
Bundle everything together, cross(-compile) our fingers and pray.

The prayer doesn't help. But let's see what does...
Continue reading "Cross Compile TensorFlow C++ app for the Jetson TK1"

Share

Cross-compile latest Tensorflow (1.5+) for the Nvidia Jetson TK1

Been looking around for a solid resource on how to get Tensorflow to run on the Jetson TK1. Most what I found was how to get TF 0.8 to run, which was the last TF version to allow usage of cuDNN 6 that is the latest version available for the TK1.

The TK1 is an aging platform with halted support, but it is still a cheap option for high-powered embedded compute. Unfortunately, being so outdated it's impossible to get the latest and greatest of DNN to work on the CUDA GPU on the TK1, but we can certainly use the CPU!
So a word of disclaimer - this compiled TF version will not use the GPU, just the CPU. However, it will let you run the most recent NN architectures with the latest layer implementations.

Cross compilation for the TK1 solves the acute problem of space on the device itself, as well as speed of compilation. On the other hand it required bringing up a compilation toolchain, which took a while to find.

I am going to be assuming a Ubuntu 16.04 x86_64 machine, which is what I have, and really you can do this in a VM or a Docker container just as well on Windows.

Continue reading "Cross-compile latest Tensorflow (1.5+) for the Nvidia Jetson TK1"

Share

An automatic Tensorflow-CUDA-Docker-Jupyter machine on Google Cloud Platform


For a class I'm teaching (on deep learning and art) I had to create a machine that auto starts a jupyter notebook with tensorflow and GPU support. Just create an instance and presto - Jupyter notebook with TF and GPU!
How awesome is that?

Well... building it wasn't that simple.
So for your enjoyment - here's my recipe:
Continue reading "An automatic Tensorflow-CUDA-Docker-Jupyter machine on Google Cloud Platform"

Share

FFMpeg with Lame MP3 and streaming for the Arduino Yun

So, I've been trying to stream audio off of a USB microphone connected to an Arduino Yun.
Looking into it online I found some examples using ffserver & ffmpeg, which sounded like they could do the trick.
However right from the start I've had many problems with playing the streams on Android and iOS devices.
Seems Android likes a certain list of codecs (http://developer.android.com/guide/appendix/media-formats.html) and iOS like a different set of codecs (Link here), but they do have on codec in common - good ol' MP3.
Unfortunately, the OpenWRT on the Arduino Yun has an ffmpeg build which does not provide MP3 encoding... it does have the MP3 muxer/container format, but streaming anything other then MP3 in it (for example MP2, which the Yun-ffmpeg does have) simply doesn't work on the Android/iOS.
From experiments streaming from my PC a ffmpeg/libmp3lame MP3 stream, it looks like the mobile devices are quite happy with it - so I will need to recompile ffmpeg with Lame MP3 support to be able to stream it.
Continue reading "FFMpeg with Lame MP3 and streaming for the Arduino Yun"

Share

Push a file to your Smartphone

This is a quick tip. If you need to push a notification to your smartphone, or even send a file, I recently stumbled upon "Pushbullet".
I was looking for a solution to send a file (with automatic download) to my phone, via bash script on my raspberry pi. I've been using pushover for a while, but as far as I know, it doesn't support files

I have read the Pushbullet API, and came to realise that sending a file have 3 steps

1. Getting credentials to send the file
2. Upload the file to a remote server
3. Send a notification of "file" type with the download url

Of course, you can do 1 and 2 youself if you have access to a place which stores the file (I also managed to send a dropbox download link)

You need to sign up for Pushbullet via web, to get the api key, and also install the app on your smartphone (obviously)

So here is the bash script (It's not elegant - but it works)
Continue reading "Push a file to your Smartphone"

Share

Share NFS from Windows

I recently bought a second raspberry pi, for the purpose of making it a "dumb" media center running XBMC (Raspbmc to be exact). I already have a media center PC running XBMC on Windows 7, and I wanted to connect my raspberry pi to the downloaded media, stored remotely on the Win7.

First, of course, I tried SMB (windows share). It worked… ok. But after installing a new HP Wireless printer, it seemed to disconnect a lot. I don't fully understand why, but it appears that the printer publishes itself as SMB master thus disconnecting my other SMB connections (or maybe only Linux ones)

Anyways, I have spent almost two days, understanding how to connect the Raspberry pi to Windows 7 using NFS. It was not easy, because it seems Microsoft has dropped support for it on home OS (even Win7 ultimate) since Windows XP.

I ended up doing it with Cygwin (which gives powerful Linux capabilities to windows machines).

I want to outline what I have done in order for this to work. This process could be very easy and it could be frustrating. I really hope it will help you do it yourself.

So it might do the trick as step-by-step, and you might come some obstacles on the way

The original guide I used can be found in this link, however it did not work at once and I had to tweak a bit. Also, it is referring to Windows XP.

As this is not step-by-step in full, with screenshots, it might help you on your journey. This can also help you with any windows share to be exported to linux

Here it is: Continue reading "Share NFS from Windows"

Share

Tailing the output of multiple files in Linux

This is a quick post to show a trick to tail multiple files, while showing the filename in the beginning of the line

What I needed was a way to grep multiple logs for an exception. But doing "tail -f *.log | grep exception" only let me see the exception, but I didn't know which log file to look in

I have found this guide, and altered the script and added

  1. Printing the file name in the beginning of each line
  2. Padding spaces after the file name (you can alter the minimal length in the ALIGN variable

Anyway - here's the script. Hope you find it useful

#!/bin/bash
 
# When this exits, exit all back ground process also.
trap 'kill $(jobs -p)' EXIT
 
ALIGN=31
 
# iterate through the each given file names,
for file in "$@"
do
        LENGTH=<code>echo ${file} | wc -c</code>
        PADDING=<code>expr ${ALIGN} - ${LENGTH}</code>
        PAD=<code>perl -e &quot;print ' ' x $PADDING;&quot;</code>
 
        # show tails of each in background.
        tail -f $file | sed &quot;s/^/${file}${PAD}:/g&quot;  &amp;
done
 
# wait .. until CTRL+C
wait
Share

Using your Raspberry Pi as an SSL Proxy

Not long ago, I have purchased an IP camera for my home. A nice toy I must say. I wanted to expose this camera for outside access. The issue is that this camera's interface does not support SSL.

Well because privacy is involved, the least I could do is add SSL somehow. I googled a bit and came across this article. I decided to use my raspberry pi for that.

The process itself is relatively easy but I had to do some improvisations over the article above. So I decided to make a tutorial for this.

You can use this to add SSL layer on top of every http you have.

So here we go: Continue reading "Using your Raspberry Pi as an SSL Proxy"

Share