Computer Vision News - September 2016
It’s more than a deep learning package, it’s an architecture! We showed you in our issue of August how to use TensorFlow as a framework for doing computer vision; specifically we demonstrated, with a simple example, how to find the grid lines in a picture of a Sudoku puzzle. In this month's issue we will expand this example and demonstrate more advanced techniques in TensorFlow: (1) Modular programming - splitting the code and having a graph with a pipeline of multiple functions, each doing one independent piece of code; (2) Function parameters - having function’s parameters being part of the TensorFlow graph and changing/updating those parameters via the graph; (3) Queue reader - analyzing batches of files and maintaining them in parallel via the queue reader thread. First, a brief recap of what we did in our last issue : we used the getHoughlines function for finding the straight lines in a given image. The function starts by converting the image into grayscale. Next, it extracts the edges in the grayscale image using the Canny edge detector. Then, it invokes the HoughLines function which finds the lines in the image with the Hough transform. 14 Computer Vision News Tool TensorFlow - Part 2 Tool The code for executing this with TensorFlow is as follows: def getHoughlines(img): image = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) gray = cv2.convertScaleAbs(image) edges = cv2.Canny(gray, 10, 150, apertureSize=3) lines = cv2.HoughLines( edges,1.0, np.pi , 200) return lines import tensorflow as tf # place holder - a tensor that will always be fed with the input image sudoku = tf.placeholder(tf.float32, shape=shape, name='sudokuP') # Hough Transform warper board_update= tf.py_func(getHoughlines,[sudoku],[tf.float32], name='HoughF') # Read the image and invoke the getHoughlines by TensorFlow filename = 'sudoku.png' raw_image_data = cv2.imread(filename) with tf.Session() as session: session.run(tf.initialize_all_variables()) lines = session.run(board_update, feed_dict={sudoku: raw_image_data})[0] Let’s now start adding some new stuff! (1) Modular programming We will demonstrate how to make the code more modular. TensorFlow has a built-in support for defining a pipeline of functions, each processing the output of the function before it.
Made with FlippingBook
RkJQdWJsaXNoZXIy NTc3NzU=