/AI • 4 min read

Playing with TensorFlow in less than 5 min thanks to its Docker Image

Artificial Intelligence is one of these fascinating topics, which I both find too complex to really understand, and too important to not try anyway.

If you just want to dip your toe and understand why it’s fascinating, you HAVE TO read Wait But Why serie on AI Revolution.

Then if you want to actually try, you can play with TensorFlow, a Machine-Learning software, recently open-sourced by Google. And giving it away for free doesn’t mean it’s obsolete. Quite the opposite actually.

The easiest way to get started is to use the TensorFlow Docker image. Instead of installing specific dependencies on your machine, we’ll let Docker do its magic.

Install Docker on macOS / OS X

There’s now a Docker for Mac app (which replaces the older Docker Toolbox).

I suggest you install Homebrew + Cask once and for all:

# install Homebrew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

# install Cask
brew tap caskroom/cask

Then install the cask for Docker for Mac:

brew cask install docker

Alternatively, you can install Docker for Mac manually by following these instructions.

Let Docker install, and once finished you should have the whale icon in your menubar.
Click on the whale icon > Preferences, and unless you want to use Docker for actual work, I suggest to not automatically start Docker when you log in, and exclude VM from Time Machine backups.

Edit Docker for Mac settings

Install Docker on other OS

See instructions on Docker website.

Run the TensorFlow Docker image

As stated in the official doc, start TensorFlow with this command, and it will automatically download and start the TensorFlow docker image:

docker run -it -p 8888:8888 gcr.io/tensorflow/tensorflow

You can use the same command later, it will be a lot faster as it won’t need to download the Docker image again.

If everything’s ok, you can open http://localhost:8888/ and see the Jupyter notebook.

Jupyter notebook

To close it, just CTRL+C then y in the terminal where it’s running.

Let’s do something fun

So you have a Machine-Learning piece of software running on your machine.

Ok, I don’t know what else I can do with it, or even what Jupyter is. But just think about that. Your crappy laptop is now an artificial intelligence powerhouse. How cool is that! 🤓

Anyway, here’s a fun script you can try. It’s an image recognition model called Inception-v3, and basically analyzes pictures and gives suggestions on what they could be.

You can start this script with the Imagenet Docker image:

docker run atong01/imagenet-tensorflow python classify_image.py

Without any other arguments, the image recognition is done on the following picture:

Tensorflow image recognition candidate

Which gives this result:

giant panda, panda, panda bear, coon bear, Ailuropoda melanoleuca (score = 0.89233)
indri, indris, Indri indri, Indri brevicaudatus (score = 0.00859)
lesser panda, red panda, panda, bear cat, cat bear, Ailurus fulgens (score = 0.00264)
custard apple (score = 0.00141)
earthstar (score = 0.00107)

Pretty good, that’s a panda!

Now, to get some fun, let’s provide our own pictures and see what’s suggested:

docker run -v $PWD:/root/tmp:ro atong01/imagenet-tensorflow python classify_image.py --image_file tmp/$(IMAGE)

Note: you have to replace $(IMAGE) with your actual picture filename, and to make things easier, you should run this command from the directory where your pictures are.

And here are the results:


Brabancon griffon (score = 0.58555)
muzzle (score = 0.06878)
sunglasses, dark glasses, shades (score = 0.05402)
malinois (score = 0.04838)
Chihuahua (score = 0.03987)


wig (score = 0.42651)
microphone, mike (score = 0.07809)
wool, woolen, woollen (score = 0.06955)
cardigan (score = 0.06377)
bow tie, bow-tie, bowtie (score = 0.01920)


scuba diver (score = 0.94702)
oxygen mask (score = 0.01505)
snorkel (score = 0.00399)
parachute, chute (score = 0.00329)
comic book (score = 0.00145)


parachute, chute (score = 0.26203)
stretcher (score = 0.11104)
gasmask, respirator, gas helmet (score = 0.05308)
ski (score = 0.03529)
solar dish, solar collector, solar furnace (score = 0.03124)

What’s your funniest picture?

If you wanna learn more about Machine Learning and TensorFlow, you can participate in the Deep Learning MOOC from Google.

Subscribe to Til' You Make It!
Get the latest posts delivered right to your inbox.
No Spam, No Bullshit. Unsubscribe Anytime.

Want to be smart and loved? Share this article!