Code examination

At this point, our environment should be ready for the main code section. Let's now look at each section of that code to understand its purpose. 

The first section performs various additional imports. Take specific note of the line of code that imports the Visual Recognition service (VisualRecognitionV3) from the (now upgraded) watson_developer_cloud:

from watson_developer_cloud import VisualRecognitionV3

The following are the commands:

import numpy as np
import os
import six.moves.urllib as urllib
import sys
import tarfile
import tensorflow as tf
import zipfile
import json
from io import StringIO
from PIL import Image
from watson_developer_cloud import VisualRecognitionV3
import matplotlib.pyplot as plt
import matplotlib.patches as patches

The next line of code uses our previously mentioned API key (you'll use your own):

# --- Replace with your api key
visual_recognition = VisualRecognitionV3('2016-05-20', api_key='r-1m0OdmBy9khRHJvujylJoLRJIqjwS6Bqwb6VMBfeCE')

The next section contains variables that you can experiment with when you run the notebook. Look at the results and adjust the variables to see the effects:

MAX_NUMBER_OF_BOXES = 9
MINIMUM_CONFIDENCE = .9
COLORS = ['b', 'g', 'r', 'c', 'm', 'y', 'b', 'w']

From the preceding commands, let's explore each of the three variables defined:

  • MAX_NUMBER_OF_BOXES: This variable represents the maximum number of objects to locate within you test image; I used 9 because it can get ugly if there are a lot of them.
  • MINIMUM_CONFIDENCE: This variable represents the minimum confidence score that a box can have. If this value is too low, you may end up with boxes around nothing.
  • COLORS: This variable sets the resulting identification boxes' attributes.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset