Exemplo n.º 1
0
def config(model_def, pretrained_model, gpu, image_dim, image_mean_file):
  global IMAGE_DIM, CROPPED_DIM, IMAGE_CENTER, IMAGE_MEAN, CROPPED_IMAGE_MEAN
  global NET, BATCH_SIZE, NUM_OUTPUT

  # Initialize network by loading model definition and weights.
  t = time.time()
  print("Loading Caffe model.")
  NET = caffe.CaffeNet(model_def, pretrained_model)
  NET.set_phase_test()
  if gpu:
    NET.set_mode_gpu()
  print("Caffe model loaded in {:.3f} s".format(time.time() - t))

  # Configure for input/output data
  IMAGE_DIM = image_dim
  CROPPED_DIM = NET.blobs()[0].width
  IMAGE_CENTER = int((IMAGE_DIM - CROPPED_DIM) / 2)

    # Load the data set mean file
  IMAGE_MEAN = np.load(image_mean_file)

  CROPPED_IMAGE_MEAN = IMAGE_MEAN[IMAGE_CENTER:IMAGE_CENTER + CROPPED_DIM,
                                  IMAGE_CENTER:IMAGE_CENTER + CROPPED_DIM,
                                  :]
  BATCH_SIZE = NET.blobs()[0].num  # network batch size
  NUM_OUTPUT = NET.blobs()[-1].channels  # number of output classes
Exemplo n.º 2
0
 def __init__(self, model_def_file, pretrained_model, center_only = False,
     num_output=1000):
   if center_only:
     num = 1
   else:
     num = 10
   self.caffenet = caffe.CaffeNet(model_def_file, pretrained_model)
   self._output_blobs = [np.empty((num, num_output, 1, 1), dtype=np.float32)]
   self._center_only = center_only
Exemplo n.º 3
0
    FLAGS(sys.argv)

    ## Load list of image filenames and assemble into batches.
    t = time.time()
    print('Assembling batches...')
    with open(FLAGS.images_file) as f:
        image_fnames = [_.strip() for _ in f.readlines()]
    image_batches = assemble_batches(image_fnames, FLAGS.crop_mode,
                                     FLAGS.batch_size)
    print('{} batches assembled in {:.3f} s'.format(len(image_batches),
                                                    time.time() - t))

    # Initialize network by loading model definition and weights.
    t = time.time()
    print("Loading Caffe model.")
    caffenet = caffe.CaffeNet(FLAGS.model_def, FLAGS.pretrained_model)
    caffenet.set_phase_test()
    if FLAGS.gpu:
        caffenet.set_mode_gpu()
    print("Caffe model loaded in {:.3f} s".format(time.time() - t))

    # Process the batches.
    t = time.time()
    print 'Processing {} files in {} batches'.format(len(image_fnames),
                                                     len(image_batches))
    dfs_with_feats = []
    for i in range(len(image_batches)):
        if i % 10 == 0:
            print('Batch {}/{}, elapsed time: {:.3f} s'.format(
                i, len(image_batches),
                time.time() - t))