Category Archives: Python

TensorFlow and deep learning, without a PhD

Excellent introductory video from Google’s Martin Gorner covering the handwritten 0-9 digits recognition problem using the MNIST data set.  Code is Python using the Tensorflow library.

He begins with a single layer network, progresses into a multi-layer network and ends with a convolutional neural network, showing how improvements in techniques correspond to better test accuracy.

Covers softmax, sigmoid, ReLU, matrix transformation, convolutional networks, over-fitting, test and training accuracy.

Well worth a watch for beginners and has better explanations than some full courses online.

Note: they figure out the microphone feedback situation around minute 15 or 16.

 

Flip Image OpenCV Python

OpenCV provides the flip() function which allows for flipping an image or video frame horizontally, vertically, or both.

 

Reference:

OpenCV documentation:  http://docs.opencv.org/2.4/modules/core/doc/operations_on_arrays.html#flip

Open Multiple Images with OpenCV in Python

Building on our previous example of opening a single image, this guide will explain how to open multiple images. The easiest way to load multiple images is to put all the images into a single folder and loop through the directory opening each one.

This guide doesn’t introduce any new OpenCV functions you shouldn’t already be familiar with from the previous example, but we will include new packages os and os.path to make a list of images to process.

The code

A note on OpenCV image support from the OpenCV docs (http://docs.opencv.org/2.4/doc/tutorials/introduction/display_image/display_image.html)

Note OpenCV offers support for the image formats Windows bitmap (bmp), portable image formats (pbm, pgm, ppm) and Sun raster (sr, ras). With help of plugins (you need to specify to use them if you build yourself the library, nevertheless in the packages we ship present by default) you may also load image formats like JPEG (jpeg, jpg, jpe), JPEG 2000 (jp2 – codenamed in the CMake as Jasper), TIFF files (tiff, tif) and portable network graphics (png). Furthermore, OpenEXR is also a possibility.

Boilerplate code

 

Open an Image with OpenCV in Python

The following code will get you started to load and display an image with OpenCV and Python.

OpenCV functions used:

The code

 

Boilerplate code

 

Where to next?

Install OpenCV 3.x with Python 2.7 on Ubuntu

Updated: 10/11/2016

How to Install OpenCV 3.x and Python 2.7+ on Ubuntu

Step 1:

Open a terminal window and update the apt package manager lists and upgrade any currently installed packages:

Step 2:

Install developer tools:

Step 3:

Install packages to open image formats including JPEG, PNG, TIFF, and others:

Step 4:

Install the GIMP toolkit (GTK+) which OpenCV uses to build GUIs:

Step 5:

Install packages to open video formats:

Step 6:

Install libraries that optimize various routines in OpenCV:

Step 7:

Install pip, a package manager for Python:

https://pip.pypa.io/ is the official pip website

Step 8:

Install Python 2.7 development tools:

Step 9:

Install numpy because OpenCV stores images as NumPy arrays

This post follows, updates and adds to the instructions from Py Image Search here: http://www.pyimagesearch.com/2015/06/22/install-opencv-3-0-and-python-2-7-on-ubuntu/

MLBD Machine Learning is Fun! Part 3: Deep Learning and Convolutional Neural Networks

Here we follow along with the 3rd part of Adam Geitgey’s excellent introductory series Machine Learning is Fun! “Deep Learning and Convolutional Neural Networks”

For the original article, click here.

The example presented is an object recognition classifier to determine whether or not something is a bird.  To complete this tutorial you will need:

  • TFLearn
  • TensorFlow
  • Python 2.7
  • Birds and not birds data set

 

Original test script

CC: “Python for Informatics” Open Textbook Remixed in 11 Days

Image: dr-chuckCC BY

 

Chuck Severance, clinical professor at the University of Michigan’s School of Information, recently published a new textbook in 11 days because he was able to remix an existing textbook. The book, Python for Informatics: Exploring Information, is currently being used in his winter semester Networked Computing course. The textbook is based on the openly licensed book Think Python: How to Think like a Computer Scientist by Allen B. Downey. Students are able to take advantage of the University Library’s Espresso Book Machine to print on-demand copies for approximately $10. Python for Informatics is available under a CC BY-SA license.

Severance explains, “the book is a cool example of a situation where I’ve finally got to the ‘remixing’ bit of the Open promise.” The first 10 chapters are done and eight more are planned for completion by April 2010. Read more of Chuck’s thoughts about remixing an open book.

Creating this open textbook was a part of a larger effort by Chuck to support his course with openly licensed  content, and current versions of lecture slides and videos are published via the PythonLearn website.  In a past iteration of the course, Chuck went through the dScribe process developed by Open.Michigan to create an OER version of SI 502, available under a CC BY license.

Building an Image Processing Pipeline Overview

This post is intended to kick off a multi-part series on building an image processing pipeline.  Presented here is an outline which will be updated and modified along the way.

My motivation and the goal is to build a process that ingests photos (currently from a mobile device), sort them into multiple categories, and perform an independent task on each photo after sorting.

The secondary goal is to build a toolkit of scripts for each of these tasks that are reusable in the future.

The programming will be in Python.

Pipeline overview:

  1. Mobile image capture device (iPhone)
  2. Program to sync photos with a computer (BitTorrent Sync)
  3. Directory spy to process newly synced images
  4. Indexing/de-duplication
  5. Pre-processing
  6. Processing
  7. Final result

Progress so far:

Numbers one and two are easily crossed off the list.  I have created a directory spy (item #3)  in the past, but it needs to be reviewed and modified to work here.

Getting started on Algorithmia

 

algorithmia-logo

Updated for 2016 – For the previous version see: Getting Started on Algorithmia 2015

Algorithmia URL: https://algorithmia.com/

For languages it currently supports:

Also new as of 5/19/16 support for:

For source code the options are

  • Open Source
  • Closed Source

The open source licence options are

  • Algorithmia Platform License
  • Apache License 2.0
  • GNU GPL v3.0
  • MIT License

The closed source licence options are

  • Algorithmia Platform License
  • Apache License 2.0
  • GNU GPL v3.0

I wasn’t able to find the details of their “Algorithmia Platform License” and plan to reach out to them for more details.

For calling your algorithms they provide sample code in the API documentation: http://docs.algorithmia.com/

Provided samples are:

Note: In the source code examples, while logged in, it pre-fills your API key into the example code.  All except for the Scala example (it always uses “c6ca861e50054f63a0fc74b5f845bc1a”)

The Python code they provide is for the 2.x version.  For 3.x version see my sample code.

It looks like the commented out HTML navigation items from my 2015 edition either were never implemented or are still on the rodamap:

  • Clone Algorithm
  • Run Locally
  • Submit Algorithm

Resources