Darwin
1.10(beta)
|
This project provides a reference implementation for the "Superpixel Graph Label Transfer with Learned Distance Metric" work of Gould et al. (ECCV 2014). The project is part of the Darwin software package. Installation instructions and addtional documentation can be found at http://drwn.anu.edu.au.
The project comprises a number of C/C++ applications for building graphs over superpixels (or regions), learning distance metrics, and performing label transform. Below are step-by-step instructions for running the project pipeline and evaluating results. The Python script nnGraphPipeline.py
in the projects/nnGraph/examples
directory runs the entire pipeline.
This project requires training instance consisting of an image and corresponding pixel annotations (for label transfer). The pixel annotations can be in the form of an integer matrix (text file) the same size as the image or a colour-coded image. The application convertPixelLabels
in the drwnProjMultiSeg project can be used to generate the text file format from colour-coded images.
Images and label files should have the same basename (e.g., img001.jpg
and img001.txt
) and may be stored in the same or different directories. By default the code assumes that images are stored in data/images
and labels stored in data/labels
with file extensions ".jpg"
and ".txt"
, respectively.
The following XML configuration can be used to change the behaviour of the move-making graph optimization algorithm. You can also change the default location of the images, labels, and regions as well as their extensions by modifying the appropriate option.
The project uses colors to visualize semantic classes. These are defined in the multi-class segmentation configuration. An example for the 21-class MSRC dataset is shown below:
Other standard Darwin configuration settings can also be controlled through the XML file.
The first step is to create a set of overlapping superpixels (or regions) for each image. These will be stored in a drwnSuperpixelContainer object, one for each image. The object is saved in the data/regions
directory.
The following shell code snippet demonstrates how to generate superpixels for each JPEG image in the data/images
directory. If file with the same basename already exists in data/regions
then superpixel generation is skipped for that image.
Here ${BIN_DIR}
should be set to the Darwin bin
directory. The "-g"
flags specify the rough scale of the image over-segmentation (from 24-by-24 down to 4-by-4). The "-m
SUPERPIXEL"
flag can be changed to "-m SLIC"
for SLIC superpixels. The application visualizeSuperpixels
can be used to visualize the resulting set of superpixels.
After generating superpixels for each image in the training set we initialize the superpixel graph by adding a node for every superpixel. We also associate a feature vector (and class label) with each node. The following code will read all images in the MSRC training and validation sets (specified in msrcTrainValList.txt
) and add them to a graph. The graph is saved as "nnMSRC.init_train"
.
We pre-process the test set in the same way for later evaluation.
We could build our nearest neighbour graph based on the raw features (using Euclidean distance). However, better results are possible if we learn a distance metric appropriate to the task. The nnGraphLearnTransform
application allows various distance metrics to be learned. Note that once the distance metric is learned we apply a transformation to the feature vectors so that evaluating the Euclidean distance on the transformed features is equivalent to evaluating the learned distance metric on the raw features.
The following shell commands learn a distance metric based of the Large-Margin Nearest Neighbor (LMNN) algorithm of Weinberger and Saul (JMLR, 2006) and then transforms the training set features ready for finding nearest neighbours.
We are now ready to add and optimize the edges in our graph so that they reflect nearest neighbour matches over superpixels. The code first adds edges randomly and then proceeds to find better matches through a sequence of search moves. You can change which search moves get run in the nnGraphConfig.xml
file.
We are now ready to evaluate performance on the test set. We first add nodes corresponding to superpixels from image in the test set to the graph (applying the appropriate feature transformation).
Next we add and optimize edges from images in the test set to those in the training set. We do this on all test set images simultaneously. The fact that we have already built a graph over training set images helps the move making algorithm to find good matches quickly.
"-eqv msrcTestList.txt"
option ensures that we do not add edges between any two images coming from the test set.We can now transfer labels from the training set images to the test set images and evaluate accuracy.
The code will print global and class-averaged accuracy. Annotated images are also saved in the output
directory (with extension ".lmnn_5.png"
).
We can also process images one at a time. This is useful for labeling novel images. The first step is to create and save regions/superpixels for the novel image.
Next we can use the nnGraphOnlineLabelTransfer
application to connect the novel image to the nearest neighbour graph and perform label transfer. The following command line shows how to use the previously learned distance metric and graph to transfer labels onto an unseen image.
-labelCache
option.