Build a classifier based on IBM Watson Visual Recognition Service, and test it by classifying both positive and negative images. Given a threshold, divide the scores fetched from server to true or false. By all these data, calculate ROC.
This program is to randomly select some amount of positive and negative pictures for training for a classifier, and some amount of positive and negative pictures for testing the classifier. Then automatically calculate all scores to get ROC points, Confidence Intervals, and draw ROC plot.
-
This project is based on IntelliJ 14.1.5, so please open it with it.
-
Edit the
info.propertiesfile to give necessary information the program needs. -
There is a
resourcedirectory, where you can put your own pictures there. Default setting for the path is set toresourcedirectory. That means if you put your pictures there, you should deletePOSITIVE_DIRECTORY_PATHandNEGATIVE_DIRECTORY_PATHproperties in theinfo.propertiessince the program doesn't need those values; -
You can also put your images anywhere, but you should add
POSITIVE_DIRECTORY_PATHandNEGATIVE_DIRECTORY_PATHto point to your directory's path. -
There are 4 main methods in
Handlerclass, two of which are to create a new classifier, another two are to classify images. -
For the 2 training methods, one of them creates a new classifier by selecting random positive and negative images, while another creates a new classifier with rotated images generated from previous training.
-
For the 2 classifying methods, one of them selects randomly some images as testing images and test the classifier on the server. Another classifies images in a directory directly,
-
Since there is a limit of images count in any zip file, 20, if the number of images is more than 20, the methods will automatically split those files into several zip files and test them one by one.
-
The resource structure should be like below (pay attention to
positivedirectory's path):CVProject |---- resource | |---- pictures | | |---- positive | | | |---- cat | | | | |---- cat1.jpg | | | | |---- ... | | | |---- dog | | |---- negative | | | |---- neg1.jpg | | | |---- ... | |---- scores(save scores as json format)
-
Add necessary dependencies by maven. All 3rd party libraries are listed there.
-
In
Mainclass, there are 4 handle methods, all of which are commented. Read the comments and choose one to run. Classifying methods return aMapwith positive and negative scores. With some lines of code below the call, it calculates the TPRs and FPRs to get ROC points and draw the plot. There are also 2 methods inDrawer, one of which is to draw a single line, another is to draw 2 lines, one normal, and another's classifier is trained with rotated images. -
In
Mainclass, callHandler.getCI(), the program will runCITimestimes to get Confidence Intervals and print the result to the console with a specific format.