default=150000)
 optionParser.add_option('-t',
     dest='num_iterations',
     help="Number of k-means iterations",
     type=int,
     default=15)
 (options,args) = optionParser.parse_args()
 
 # -- Usage
 if None in [options.feature_file, options.index_file, options.num_clusters]:
     optionParser.print_help()
     sys.exit(0)
     
 # -- Load the feature file
 log.info("Loading the feature file...")
 f = FeatureList(options.feature_file)
 f.process()
 log.debug("Loaded %s rows" % len(f.dataset))
 
 # -- Load the index
 log.info("Loading the index file...")
 flann = FLANN(log_level='info')
 flann.load_index(options.index_file,f.dataset)
 
 # -- Cluster all of the points
 log.info("Clustering into %i clusters, over %i iterations" %
     (options.num_clusters,options.num_iterations))
 cluster_data = flann.kmeans(f.dataset,options.num_clusters,dtype=uint8,
     max_iterations=options.num_iterations)
 
 # -- Save the clusters to file
    image_list = file(opts.image_list,'r')
    image_filenames = [line.strip() for line in image_list.readlines()]
    
    # -- Read in the number of features per file
    feature_count = dict()
    feature_size_list = file(opts.feature_size_list,'r')
    for image in image_filenames:
        feature_count[image] = int( feature_size_list.readline() )
    log.info( "Loaded information for %i images" % len(feature_count) )
    
    # -- Sanity check.  The first image, has 380 features.
    assert 380 == feature_count['00004fc7eb4bf00ba434c167890b99fa.jpg']
    
    # -- Load the feature file
    log.info("Loading features from file...")
    f = FeatureList(opts.feature_file)
    f.process()
    log.debug("Loaded %s rows" % len(f.dataset))

    # -- Load the clusters
    log.info("Loading clusters from file")
    cluster_file = file(opts.cluster_file,'r')
    base = basename(opts.cluster_file)
    clusters = imp.load_source(base,opts.cluster_file).clusters
    
    # -- Load the clusters into FLANN as if they were the points
    log.info("Building cluster index...")
    flann = buildIndex(clusters)
    
    # -- For each point in the feature list, find its 'nearest neighbor',
    # i.e. which cluster it belongs to.
    image_list = file(opts.image_list, 'r')
    image_filenames = [line.strip() for line in image_list.readlines()]

    # -- Read in the number of features per file
    feature_count = dict()
    feature_size_list = file(opts.feature_size_list, 'r')
    for image in image_filenames:
        feature_count[image] = int(feature_size_list.readline())
    log.info("Loaded information for %i images" % len(feature_count))

    # -- Sanity check.  The first image, has 380 features.
    assert 380 == feature_count['00004fc7eb4bf00ba434c167890b99fa.jpg']

    # -- Load the feature file
    log.info("Loading features from file...")
    f = FeatureList(opts.feature_file)
    f.process()
    log.debug("Loaded %s rows" % len(f.dataset))

    # -- Load the clusters
    log.info("Loading clusters from file")
    cluster_file = file(opts.cluster_file, 'r')
    base = basename(opts.cluster_file)
    clusters = imp.load_source(base, opts.cluster_file).clusters

    # -- Load the clusters into FLANN as if they were the points
    log.info("Building cluster index...")
    flann = buildIndex(clusters)

    # -- For each point in the feature list, find its 'nearest neighbor',
    # i.e. which cluster it belongs to.