Skip to content

Commit

Permalink
added mAP computation and a couple of others
Browse files Browse the repository at this point in the history
  • Loading branch information
Relja committed Feb 29, 2016
1 parent e5ffe0e commit 116e190
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 4 deletions.
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# relja_matlab

> Version 1.00 (03 Dec 2015)
> Version 1.01 (29 Feb 2016)
This library contains miscellaneous utilities written by Relja Arandjelović. It is used extensively in the [NetVLAD](https://github.com/Relja/netvlad) library.

Expand All @@ -17,8 +17,16 @@ are taken from the excellent [MatConvNet](http://www.vlfeat.org/matconvnet/) lib

The functions related to MatConvNet (i.e. in folder `matconvnet`) clearly depend on:

- [MatConvNet](http://www.vlfeat.org/matconvnet/) (tested using version 1.0-beta14)
1. [MatConvNet](http://www.vlfeat.org/matconvnet/) (tested using version 1.0-beta14)

2. Optional but **highly** recommended for speed if you want to use the `relja_retrievalMAP` function (it computes the mAP for retrieval; to not use this dependency, uncomment the relevant lines in the `relja_retrievalMAP.m` file): [Yael_matlab](http://yael.gforge.inria.fr/index.html) (tested using version 438)
- To download it's easiest to go [here](http://yael.gforge.inria.fr/index.html) and download the precompiled yael_matlab binaries for your OS (e.g. [yael_matlab_linux64_v438.tar.gz](https://gforge.inria.fr/frs/download.php/file/34218/yael_matlab_linux64_v438.tar.gz))


# Changes

- **1.00** Initial public release
- **1.01** (29 Feb 2016)
- Added a few more functions needed for NetVLAD v1.01 (e.g. mAP computation)

- **1.00** (04 Dec 2015)
- Initial public release
2 changes: 1 addition & 1 deletion matconvnet/relja_simplenn_move.m
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
else
for f = {'weights', 'momentum'}
f = char(f) ;
if isprop(net.layers{l}, f)
if isfield(net.layers{l}, f) || isprop(net.layers{l}, f)
for j=1:numel(net.layers{l}.(f))
net.layers{l}.(f){j} = moveop(net.layers{l}.(f){j}) ;
end
Expand Down
11 changes: 11 additions & 0 deletions relja_dir.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
% fns= relja_dir(dirname)
%
% Author: Relja Arandjelovic ([email protected])

function fns= relja_dir(dirname)
fns= dir(dirname);
fns= sort({fns.name}');
if( length(fns)>=2 && strcmp(fns(1), '.') && strcmp(fns(2), '..') )
fns= fns(3:end);
end
end
8 changes: 8 additions & 0 deletions relja_endsWith.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
% ret= relja_endsWith(s, se)
%
% Author: Relja Arandjelovic ([email protected])

function ret= relja_endswith(s, se)
ret= length(s)>=length(se) && ...
strcmp( s( end-length(se) + [1:length(se)] ), se )==1;
end
41 changes: 41 additions & 0 deletions relja_retrievalMAP.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
% [mAP, APs]= relja_retrievalMAP(db, searcher, verbose, kTop)
%
% Author: Relja Arandjelovic ([email protected])

function [mAP, APs]= relja_retrievalMAP(db, searcher, verbose, kTop)
if nargin<3, verbose= true; end
if nargin<4, kTop= 10000; end

kTop= min(db.numImages, kTop);

APs= zeros(db.numQueries, 1);

prog= tic;

for iQuery= 1:db.numQueries
if verbose
relja_progress(iQuery, db.numQueries, ...
sprintf('%.4f', mean(APs(1:(iQuery-1)))), ...
prog);
end

if isa(searcher, 'function_handle')
ids= searcher(iQuery);
else
% this is likely to be faster:
[ids, ~]= yael_nn(searcher.db, searcher.qs(:,iQuery), size(searcher.db, 2));
% if you don't have yael_nn, do this:
% distsSq= sum( bsxfun(@minus, searcher.qs(:, iQuery), searcher.db).^2, 1 );
% [~, ids]= sort(distsSq); ids= ids';
end

isIgnore= ismember(ids, db.ignoreIDs{iQuery});
ids= ids(~isIgnore);
isPos= ismember(ids', db.posIDs{iQuery});
prec= cumsum(isPos)./[1:length(ids)];
recall= cumsum(isPos)/length(db.posIDs{iQuery});
APs(iQuery)= diff([0, recall]) * ( [1, prec(1:(end-1))]+prec )' /2;
end
mAP= mean(APs);
relja_display( '%.4f', mAP );
end

0 comments on commit 116e190

Please sign in to comment.