-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpascal_data.m
55 lines (50 loc) · 1.53 KB
/
pascal_data.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
function [pos, neg] = pascal_data(cls)
% [pos, neg] = pascal_data(cls)
% Get training data from the PASCAL dataset.
globals;
pascal_init;
try
load([cachedir cls '_train']);
catch
% positive examples from train+val
ids = textread(sprintf(VOCopts.imgsetpath, 'trainval'), '%s');
pos = [];
numpos = 0;
for i = 1:length(ids);
if mod(i,100)==0
fprintf('%s: parsing positives: %d/%d\n', cls, i, length(ids));
end
rec = PASreadrecord(sprintf(VOCopts.annopath, ids{i}));
clsinds = strmatch(cls, {rec.objects(:).class}, 'exact');
% skip difficult examples
diff = [rec.objects(clsinds).difficult];
clsinds(diff) = [];
for j = clsinds(:)'
numpos = numpos+1;
pos(numpos).im = [VOCopts.datadir rec.imgname];
bbox = rec.objects(j).bbox;
pos(numpos).x1 = bbox(1);
pos(numpos).y1 = bbox(2);
pos(numpos).x2 = bbox(3);
pos(numpos).y2 = bbox(4);
pos(numpos).id = ids{i};
end
end
% negative examples from train (this seems enough!)
ids = textread(sprintf(VOCopts.imgsetpath, 'train'), '%s');
neg = [];
numneg = 0;
for i = 1:length(ids);
if mod(i,100)==0
fprintf('%s: parsing negatives: %d/%d\n', cls, i, length(ids));
end
rec = PASreadrecord(sprintf(VOCopts.annopath, ids{i}));
clsinds = strmatch(cls, {rec.objects(:).class}, 'exact');
if length(clsinds) == 0
numneg = numneg+1;
neg(numneg).im = [VOCopts.datadir rec.imgname];
neg(numneg).id = ids{i};
end
end
save([cachedir cls '_train'], 'pos', 'neg');
end