parameters: (argv)
docstring: The main function will carry out classification.
docstring_summary: The main function will carry out classification.
docstring_tokens: The main function will carry out classification .
function: def main(argv):
    """
    The main function will carry out classification.
    """
    import gflags
    import glob
    import time
    gflags.DEFINE_string("root", "", "The folder that contains images.")
    gflags.DEFINE_string("ext", "JPEG", "The image extension.")
    gflags.DEFINE_string("model_def", "", "The model definition file.")
    gflags.DEFINE_string("pretrained_model", "", "The pretrained model.")
    gflags.DEFINE_string("output", "", "The output numpy file.")
    gflags.DEFINE_boolean("gpu", True, "use gpu for computation")
    FLAGS = gflags.FLAGS
    FLAGS(argv)
  
    net = ImageNetClassifier(FLAGS.model_def, FLAGS.pretrained_model)
  
    if FLAGS.gpu:
      print 'Use gpu.'
      net.caffenet.set_mode_gpu()
  
    files = glob.glob(os.path.join(FLAGS.root, "*." + FLAGS.ext))
    files.sort()
    print 'A total of %d files' % len(files)
    output = np.empty((len(files), net._output_blobs[0].shape[1]),
                      dtype=np.float32)
    start = time.time()
    for i, f in enumerate(files):
      output[i] = net.predict(f)
      if i % 1000 == 0 and i > 0:
        print 'Processed %d files, elapsed %.2f s' % (i, time.time() - start)
    # Finally, write the results
    np.save(FLAGS.output, output)
    print 'Done. Saved to %s.' % FLAGS.output
function_tokens: def main ( argv ) : import gflags import glob import time gflags . DEFINE_string ( "root" , "" , "The folder that contains images." ) gflags . DEFINE_string ( "ext" , "JPEG" , "The image extension." ) gflags . DEFINE_string ( "model_def" , "" , "The model definition file." ) gflags . DEFINE_string ( "pretrained_model" , "" , "The pretrained model." ) gflags . DEFINE_string ( "output" , "" , "The output numpy file." ) gflags . DEFINE_boolean ( "gpu" , True , "use gpu for computation" ) FLAGS = gflags . FLAGS FLAGS ( argv ) net = ImageNetClassifier ( FLAGS . model_def , FLAGS . pretrained_model ) if FLAGS . gpu : print 'Use gpu.' net . caffenet . set_mode_gpu ( ) files = glob . glob ( os . path . join ( FLAGS . root , "*." + FLAGS . ext ) ) files . sort ( ) print 'A total of %d files' % len ( files ) output = np . empty ( ( len ( files ) , net . _output_blobs [ 0 ] . shape [ 1 ] ) , dtype = np . float32 ) start = time . time ( ) for i , f in enumerate ( files ) : output [ i ] = net . predict ( f ) if i % 1000 == 0 and i > 0 : print 'Processed %d files, elapsed %.2f s' % ( i , time . time ( ) - start ) # Finally, write the results np . save ( FLAGS . output , output ) print 'Done. Saved to %s.' % FLAGS . output