imdb_from_voc.m 2.23 KB
Newer Older
Ross Girshick's avatar
Ross Girshick committed
1
function imdb = imdb_from_voc(root_dir, image_set, year)
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
% imdb = imdb_from_voc(root_dir, image_set, year)
%   Builds an image database for the PASCAL VOC devkit located
%   at root_dir using the image_set and year.
%
%   Inspired by Andrea Vedaldi's MKL imdb and roidb code.

% AUTORIGHTS
% ---------------------------------------------------------
% Copyright (c) 2014, Ross Girshick
% 
% This file is part of the R-CNN code and is available 
% under the terms of the Simplified BSD License provided in 
% LICENSE. Please retain this notice and LICENSE if you use 
% this file (or any portion of it) in your project.
% ---------------------------------------------------------
Ross Girshick's avatar
Ross Girshick committed
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65

%imdb.name = 'voc_train_2007'
%imdb.image_dir = '/work4/rbg/VOC2007/VOCdevkit/VOC2007/JPEGImages/'
%imdb.extension = '.jpg'
%imdb.image_ids = {'000001', ... }
%imdb.sizes = [numimages x 2]
%imdb.classes = {'aeroplane', ... }
%imdb.num_classes
%imdb.class_to_id
%imdb.class_ids
%imdb.eval_func = pointer to the function that evaluates detections
%imdb.roidb_func = pointer to the function that returns regions of interest

cache_file = ['./imdb/cache/imdb_voc_' year '_' image_set];
try
  load(cache_file);
catch
  VOCopts = get_voc_opts(root_dir);
  VOCopts.testset = image_set;

  imdb.name = ['voc_' year '_' image_set];
  imdb.image_dir = fileparts(VOCopts.imgpath);
  imdb.image_ids = textread(sprintf(VOCopts.imgsetpath, image_set), '%s');
  imdb.extension = 'jpg';
  imdb.classes = VOCopts.classes;
  imdb.num_classes = length(imdb.classes);
  imdb.class_to_id = ...
    containers.Map(imdb.classes, 1:imdb.num_classes);
  imdb.class_ids = 1:imdb.num_classes;

  % private VOC details
  imdb.details.VOCopts = VOCopts;

  % VOC specific functions for evaluation and region of interest DB
  imdb.eval_func = @imdb_eval_voc;
  imdb.roidb_func = @roidb_from_voc;
  imdb.image_at = @(i) ...
      sprintf('%s/%s.%s', imdb.image_dir, imdb.image_ids{i}, imdb.extension);

  for i = 1:length(imdb.image_ids)
    tic_toc_print('imdb (%s): %d/%d\n', imdb.name, i, length(imdb.image_ids));
    info = imfinfo(sprintf(VOCopts.imgpath, imdb.image_ids{i}));
    imdb.sizes(i, :) = [info.Height info.Width];
  end

  fprintf('Saving imdb to cache...');
  save(cache_file, 'imdb', '-v7.3');
  fprintf('done\n');
end