I implemented the code to learn multiple images at once in the Watson Visual Recognition Collection in Java.

Introduction

When putting data into the Watson Visual Recognition Collection, you have to implement the code one by one except for writing the code, which is troublesome. This time, I implemented the code that can train multiple images at once with Java code.

Java execution environment construction

  1. JDK installation Install the JDK from the URL below. http://www.oracle.com/technetwork/java/javase/downloads/index.html

Please refer to the following URL for the installation method. http://qiita.com/hiesiea/items/54e49dabfb5606edb54d#2-jdk%E3%81%AE%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%BC%E3%83%AB    2. Install eclipse Install eclipse from the following URL. http://www.eclipse.org/downloads/

Please refer to the following URL for the installation method. http://qiita.com/hiesiea/items/54e49dabfb5606edb54d#3-eclipse%E3%81%AE%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%BC%E3%83%AB    3. Create Maven project Create "New"-> "Project"-> "Maven Project" of eclipse. maven1.png

Get code, set

  1. Download code Download the code from the URL below. https://github.com/takana-at/VisualRecognition-training
    After downloading, unzip the code.
  2. Code placement Copy the following class to the sample.app project. ・AddToCollection.java ・AddToCollectionThread.java ・TrainingDefinition.java

Upload training data to Visual Recognition Collection

Creating a Visual Recognition service

  1. Create a Visual Recognition service on Bluemix. Log in to Bluemix from the URL below and create a "Catalog"-> "Watson"-> "Visual Recognition" service. https://console.bluemix.net/

  2. After creating the Visual Recognition service, check {api_key} from "Service Credentials"-> "Credentials-1" and make a note of it. visual_recognition1.png

Create Collection in Visual Recognition

  1. Create a collection in the Visual Recognition service. Access the URL below, enter the api_key you noted earlier in "Parameters"-> "api_key", enter an arbitrary name in "name", and click "try it out!". https://watson-api-explorer.mybluemix.net/apis/visual-recognition-v3#!/visual45recognition/post_v3_collections

visual_recognition2.png    2. When the collection is created, the screen below will be displayed. Make a note of the "collection_id". Also, make sure that "status" is "Available". visual_recognition3.png

Execute Java code

Run AddToCollection.java.

  1. Modify the code in AddToCollectionThread.java. Change the {api_key} in the code for this class to the api_key you noted earlier.

  2. Place the image to be uploaded. For images, create a "trainImage" folder directly under the project, create a "image ID name" folder in the "trainImage" folder, and place the image in the "image ID name" folder. This image ID is used to sort by person, so place the same person in the folder with the same image ID name.

PROJECTNAME
|-trainImage
   |-IMGID_NAME
      |-IMG  
      |-IMG

For example, the images of "m010469.jpg " and "m010462.jpg " are stored in the folder with the image ID name "female" as shown below. readd1.png

  1. Place the metafile to be uploaded. For images, create a "trainMetafile" folder directly under the project, create a folder with the same "image ID name" as in the trainImage folder in the "trainMetafile" folder, and create a folder with the same "image ID name" in the "image ID name" folder for the person related to that image ID. Place the information in a json file. At this time, the file name of the json file should be "image ID name.json". The json file stored in the "trainMetafile" folder allows you to register additional information about the image stored in trainImage.
PROJECTNAME
|-trainMetafile
   |-IMGID_NAME
      |-IMGID_NAME.json

For example, store the json file named "female.json" in the folder with the image ID name "female" as shown below. readd2.png

Please refer to the code below when creating a Metafile.

Metafile entry example(femaleA.json)


{"name":"Woman A","img_name":"femaleA","img_url":"https://model.foto.ne.jp/free/product_info.php/cPath/24_252_256/products_id/300378"}
  1. Put the following in the argument and implement. 「./trainImage」 AddToCollection2.png

  2. The execution result is as follows. add4.png

Check the Collection

Check if the training data has been added to the Collection.

  1. Access the following URL, enter the api_key and collection_id that you entered when you implemented AddToCollection.java in "Parameters"-> "api_key" and "collection_id", and click "try it out!". https://watson-api-explorer.mybluemix.net/apis/visual-recognition-v3#!/visual45recognition/get_v3_collections_collection_id_images! List100image1.png

  2. Display the list of images registered in the collection, and if the images registered in "images" of the collection are registered, the training is complete. add6.png

Recommended Posts

I implemented the code to learn multiple images at once in the Watson Visual Recognition Collection in Java.
How to call multiple names at once in the same category
Call Visual Recognition in Watson Java SDK
I tried to implement the Euclidean algorithm in Java
~ I tried to learn functional programming in Java now ~
In Java, I want to trim multiple specified characters from only the beginning and end.
Since the reading of JdbcCodeList of TERASOLUNA is slow, I tried to register multiple at once.
How to input multiple images at once using rake task
I want to simplify the conditional if-else statement in Java
Java in Visual Studio Code
[Java] I implemented the combination.
[Java] I want to check that the elements in the list are null or empty [Collection Utils]
I want to display the images under assets/images in the production environment
[Java] I want to perform distinct with the key in the object
Sample code to call the Yahoo! Local Search API in Java
[Words spelled to me when I was in the first grade ⑦] What I want you to include at least with the Visual Studio Code extension
Guess the character code in Java
How to learn JAVA in 7 days
I implemented the multiple image upload function in Rails so that multiple images can be slid for the post
I called the COTOHA API parser 100 times in Java to measure performance.
I want to get the IP address when connecting to Wi-Fi in Java
I tried to create a method to apply multiple filters at once with Java Stream API. Is this okay?
Java reference to understand in the figure
OCR in Java (character recognition from images)
I tried the new era in Java
How to get the date in java
I went to the Java Women's Club # 1
[Mac] Install Java in Visual Studio Code
Sample source code for finding the least common multiple of multiple values in Java
Sample code to get the values of major SQL types in Java + MySQL 8.0