During this lab, you will use the Visual Recognition service to train a classifier and recognize images.
You can see a version of this app that is already running here.
So let’s get started. The first thing to do is to build out the shell of our application in the IBM Cloud.
- Sign up for an IBM Cloud account.
- Download the IBM Cloud CLI.
- Create an instance of the Visual Recognition service and get your credentials:
- Go to the Visual Recognition page in the IBM Cloud Catalog.
- Log in to your IBM Cloud account.
- Click Create.
- Click Show to view the service credentials.
- Copy the
apikey
value - Copy the
url
value.
Note: The confirmation email from the IBM Cloud mail take up to 1 hour.
-
Clone the repository into your computer and navigate to the new directory.
git clone https://github.com/watson-developer-cloud/visual-recognition-nodejs.git cd visual-recognition-nodejs
-
Sign up in the IBM Cloud or use an existing account.
-
If it is not already installed on your system, download and install the Cloud-foundry CLI tool.
-
Edit the
manifest.yml
file in the folder that contains your code and replacevisual-recognition
with a unique name for your application. The name that you specify determines the application's URL, such asyour-application-name.mybluemix.net
. The relevant portion of themanifest.yml
file looks like the following:applications: - name: visual-recognition-demo command: npm start path: . memory: 512M env: NODE_ENV: production
-
Copy the credentials from the prerequisites to the application by creating a
.env
file using this format:
VISUAL_RECOGNITION_IAM_API_KEY=<your-api-key>
VISUAL_RECOGNITION_URL=<your-url>
- Install the dependencies you application need:
npm install
- Start the application by running:
npm start
- Test your application locally by going to: http://localhost:3000/
-
Login to IBM Cloud with the IBM Cloud CLI
ibmcloud login
-
Target a Cloud Foundry organization and space.
ibmcloud target --cf
-
Edit the manifest.yml file. Change the name field to something unique.
For example,- name: my-app-name
. -
Deploy the application
ibmcloud app push
-
View the application online at the app URL.
For example: https://my-app-name.mybluemix.net
The application is composed of two sections, a "Try" section and a "Train" section. The Try section will allow you to send an individual image to the Visual Recognition service to be classified.
Test out the existing service by selecting one of the provided images or pasting a URL for an image of your choice. You will see the service respond with a collection of recognized attributes about the image.
Next, try running the following image through the classifier by pasting the URL into the "Try" panel.
You'll see that it's recognized some general attributes about the image, but we want it to be able to specifically recognize it as a fruitbowl. To do that, we will need to train a customer classifier.
Navigate over to the "Train" window in the application.
Here, you will see a collection of training sets that have been provided for you. If you select any one of these, you will see that set expand to show a series of classes that will be trained, as well as negative examples of that group. For example, the Dog Breeds
classifier contains 4 classes of dogs to be identified, as well as a negative example data set of Non-dogs
.
To train the service to specifically classify a fruitbowl, we are going to use two collections of images to teach Watson what to recognize when classifying a fruitbowl. Click on the "Use your Own" box, and afterward a series of boxes will appear to allow you to upload .zip files for the classes.
Download and select the following .zip files for the classifier:
- Positive Class #1 (leftmost box) - fruitbowl.zip
- Negative Class (rightmost box) - not-fruit-bowls.zip
Once the two zip files are included, name the classifier "fruitbowl" and select the "Train your classifier" button
The classifier may take a couple minutes to train, and once it is complete the application will update to allow you to submit new images against that classifier. If you submit the original image that we used in the new prompt on the "Train" window, you will see that it will be specifically classified based on our new training!
You have completed the Visual Recognition Lab!