<jupyter_start><jupyter_text>Testing the search-and-rescue modelThis notebook demonstrates Python code for classify images using your trained Visual Recognition model.- Step 1: Install and import required libraries- Step 2: Look up Visual Recognition API key and trained model id- Step 3: View test images- Step 4: Classify the test images  Step 1: Install and import required libraries- watson_developer_cloud for working with [Watson Visual Recognition API](https://www.ibm.com/watson/developercloud/visual-recognition/api/v3/python.html?python)<jupyter_code>!pip install --upgrade watson-developer-cloud<jupyter_output><empty_output><jupyter_text>Step 2: Look up Visual Recognition API key and trained model id1. From the **Services** menu in Watson Studio right-click "Watson Services" and then open the link in a new browser tab2. In the new Watson services tab, click the service instance in the Visual Recognition list3. In the **Overview** tab, scroll down to the list of your custom models and then click "Copy model ID"4. In the **Credentials** tab, expand credentials and then copy the apikey<jupyter_code>model_id = '' # <-- PASTE YOUR MODEL ID HERE
apikey   = '' # <-- PASTE YOUR APIKEY HERE<jupyter_output><empty_output><jupyter_text>Step 3: View test imagesSample images of objects for testing your trained model.<jupyter_code>url_1 = 'https://raw.githubusercontent.com/IBMDataScience/Watson-Studio-Examples/master/Search-and-rescue/sar-model/test_images/ball.jpg'
url_2 = 'https://raw.githubusercontent.com/IBMDataScience/Watson-Studio-Examples/master/Search-and-rescue/sar-model/test_images/blocks.jpg'
url_3 = 'https://raw.githubusercontent.com/IBMDataScience/Watson-Studio-Examples/master/Search-and-rescue/sar-model/test_images/horse.jpg'
url_4 = 'https://raw.githubusercontent.com/IBMDataScience/Watson-Studio-Examples/master/Search-and-rescue/sar-model/test_images/wheelbarrow.jpg'
from skimage import io
import matplotlib.pyplot as plt
import re
fig, axs = plt.subplots( 1, 4, figsize=( 15, 60 ) )
axs[0].imshow( io.imread(url_1) )
axs[1].imshow( io.imread(url_2) )
axs[2].imshow( io.imread(url_3) )
axs[3].imshow( io.imread(url_4) )
axs[0].set_title( 'url_1: ' + re.sub( '.*\/', '', url_1 ) )
axs[1].set_title( 'url_2: ' + re.sub( '.*\/', '', url_2 ) )
axs[2].set_title( 'url_3: ' + re.sub( '.*\/', '', url_3 ) )
axs[3].set_title( 'url_4: ' + re.sub( '.*\/', '', url_4 ) )
for img in axs:
    img.set_xticks([])
    img.set_yticks([])<jupyter_output><empty_output><jupyter_text>Step 4: Classify the test images<jupyter_code># Instantiate a visual recognition object
#
from watson_developer_cloud import VisualRecognitionV3
visual_recognition = VisualRecognitionV3( version='2018-03-19', iam_apikey=apikey )
# Classify the test images
#
# *Change the url parameter (url_2, url_3, url_4) to test the different sample images
#
import json
results = visual_recognition.classify( url=url_4, threshold='0', classifier_ids=model_id ).get_result()
print( json.dumps( results, indent=2 ) )<jupyter_output>{
  "custom_classes": 4,
  "images_processed": 1,
  "images": [
    {
      "classifiers": [
        {
          "name": "search-and-rescue",
          "classes": [
            {
              "score": 0.23,
              "class": "blocks"
            },
            {
              "score": 0.005,
              "class": "car"
            },
            {
              "score": 0.013,
              "class": "horse"
            },
            {
              "score": 0.73,
              "class": "wheelbarrow"
            }
          ],
          "classifier_id": "searchxandxrescue_700952328"
        }
      ],
      "source_url": "https://github.com/IBMDataScience/Watson-Studio-Examples/raw/master/Search-and-rescue/sar-model/test_images/wheelbarrow.jpg",
      "resolved_url": "https://github.com/IBMDataScience/Watson-Studio-Examples/raw/master/Search-and-rescue/sar-model/test_images/wheelbarrow.jpg"
    }
  ]
}
{'fraction_non_alphanumeric': 0.1321664129883308, 'fraction_numerical': 0.0213089802130898, 'mean_word_length': 3.574245939675174, 'pattern_counts': {'":': 17, '<': 18, '<?xml version=': 0, '>': 16, 'https://': 7, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '417281', 'license': 'MIT', 'n_tokens_mistral': 1404, 'n_tokens_neox': 1294, 'n_words': 297, 'path': 'sar-notebooks/sar-test-notebook.ipynb', 'repo_name': 'emiactisdato/CloudData2019', 'size': '3942'}