willard-yuan / hashing-baseline-for-image-retrieval

:octocat:Various hashing methods for image retrieval and serves as the baselines
http://yongyuan.name/habir/
615 stars 255 forks source link

请问怎么跑我的实验数据呢? 需要生成mat格式吗??谢谢 #3

Closed sunyinhui closed 8 years ago

sunyinhui commented 8 years ago

如题 谢谢!!!

xysoul commented 8 years ago

在main_demo.m文件中的dataset换成你所需要跑的实验数据集,需要转换成mat格式

sunyinhui commented 8 years ago

谢谢

sunyinhui commented 8 years ago

请问mat格式是什么样的啊? <图片 标签> 这种格式吗?

willard-yuan commented 8 years ago

@sunyinhui 不是你说的这种格式的,具体什么格式你可以看看我在readme里面提供下载的几个.mat文件,你下载几个后把它们打开看看,里面保存的是图像特征以及对应的图像文件名。

xysoul commented 8 years ago

@willard-yuan 请问一下,只要是哈希算法就都可以加到这个comparison里面来吗?对于哈希算法的类型有什么要求吗?

willard-yuan commented 8 years ago

@keepmovingXY 无监督的哈希方法都可以加进来,有监督或半监督的哈希方法在数据准备这一块以及后面的评价中都需要自己另写代码。

xysoul commented 8 years ago

@willard-yuan 监督性的哈希算法处理的数据准备不是相同的吗?后面评价的代码是指对Precision和Recall等几种评价指标需要另写吗?不是很清楚,恳请指点一下

willard-yuan commented 8 years ago

@keepmovingXY 数据准备阶段差异不大,但在后面的评价时,有监督的采用的groundtruth是真实的类标记,而这里采用的是原空间测试样本的最近邻定义的groundtruth,这也是在无监督哈希方法里面比较常用的生成groundtruth的方法。

xysoul commented 8 years ago

@willard-yuan 请问检索实例是如何实现的呢?

willard-yuan commented 8 years ago

@keepmovingXY 可以参考下面这个:

% Version control:
%     V1.5 2014/09/28
%     V1.4 2014/09/16
%     V1.3 2014/08/21
%     V1.2 2014/08/16
%     V1.1 2013/09/26
%     V1.0 2013/07/22
% Author:
%     yongyuan.name

close all; clear all; clc;
addpath('./utils/');
%db_name = 'CIFAR10';
%db_name = 'CALTECH256';
db_name = 'CALTECH256CNN';

param.pos = [0:1000:10000];

loopnbits = [64];
% for CALTECH256, ID=10,14, 16=airplane
query_ID = 25; % 19 21 query_ID ranges from 1 to 1000 in cifar10 (8 retrieves horse, 13 retrieves car, 15 horses)
param.numRetrieval = 25; % Number of returned retrieval images
param.query_ID = query_ID;
param.choice = 'visualization';

%hashmethods = {'Our Method'};
hashmethods = {'Our Method', 'SELVE', 'LSH', 'SH', 'SKLSH', 'DSH', 'SpH', 'CBE-opt', 'PCAH'};
%hashmethods = {'PCA-ITQ', 'PCA-RR', 'DSH', 'LSH', 'SKLSH', 'SH', 'PCAH'};
nhmethods = length(hashmethods);

% load dataset
cons_data_name = ['pre_' db_name  '.mat'];
switch(cons_data_name)
    case 'pre_CIFAR10.mat'
        if ~exist(cons_data_name, 'file')
            load cifar_10yunchao.mat;
            db_datalabel = cifar10;
            db_data = db_datalabel(:, 1:end-1);
            exp_data = construct_data(db_name, db_data, param);
        else
            load pre_CIFAR10.mat;
        end
        clear db_data db_datalabel cifar10;
    case 'pre_CALTECH256.mat'
        if ~exist(cons_data_name, 'file')
            load Caltech256Feature/gist.mat;
            db_datalabel = feature_dataset;
            db_data = normalize1(db_datalabel(:, 1:end));
            clear db_datalabel;
            load Caltech256Feature/gabor.mat;
            db_datalabel = feature_dataset;
            db_data = [db_data normalize1(db_datalabel(:, 1:end))];
            exp_data = construct_data(db_name, db_data, param);
        else
            load pre_CALTECH256.mat;
        end
        clear db_data db_datalabel;
     case 'pre_CALTECH256CNN.mat'
        if ~exist(cons_data_name, 'file')
            load 256CNN1024dNorml.mat;
            db_datalabel = feat;
            db_data = db_datalabel(:, 1:end);
            exp_data = construct_data(db_name, double(db_data), param);
        else
            load pre_CALTECH256CNN.mat;
        end
        clear db_data db_datalabel;
end

for i =1:length(loopnbits)
    fprintf('======start %d bits encoding======\n\n', loopnbits(i));
    param.nbits = loopnbits(i);
    for j = 1:nhmethods
        [~, ~, ~, ~, ~, retrieval_list{i, j}] = demo(exp_data, param, hashmethods{1, j});
    end
end

switch(db_name)
    case 'CIFAR10'
        % show retrieval images
        load cifar-10-batches-mat/data_batch_1.mat;
        data1=data;
        labels1=labels;
        clear data labels;
        load cifar-10-batches-mat/data_batch_2.mat;
        data2=data;
        labels2=labels;
        clear data labels;
        load cifar-10-batches-mat/data_batch_3.mat;
        data3=data;
        labels3=labels;
        clear data labels;
        load cifar-10-batches-mat/data_batch_4.mat;
        data4=data;
        labels4=labels;
        clear data labels;
        load cifar-10-batches-mat/data_batch_5.mat;
        data5=data;
        labels5=labels;
        clear data labels;
        load cifar-10-batches-mat/test_batch.mat;
        data6=data;
        labels6=labels;
        clear data labels;
        database=[data1 labels1; data2 labels2; data3 labels3; data4 labels4; data5 labels5; data6 labels6];
        cifar10labels=[labels1; labels2; labels3;labels4; labels5; labels6];

        figure('Color', [1 1 1]); hold on;

        for j = 1: nhmethods
            I2 = uint8(zeros(32, 32, 3, 26)); % 32 and 32 are the size of the output image
            for i=1:(param.numRetrieval+1)
                index=retrieval_list{1, j}(i,1);
                image_r=database(index,1:1024);
                image_g=database(index,1025:2048);
                image_b=database(index, 2049:end-1);
                image_rer=reshape(image_r, 32, 32);
                image_reg=reshape(image_g, 32, 32);
                image_reb=reshape(image_b, 32, 32);
                image(:, :,1)=image_rer';
                image(:, :, 2)=image_reg';
                image(:, :, 3)=image_reb';
                image=uint8(image);
                I2(:, :, :, i) = image;
            end
            h =subplot(2, nhmethods, j);
            queryIm = I2(:, :, :, 1);
            imshow(queryIm);
            t = title('Query image');
            p = get(t,'Position');
            set(t,'Position',[p(1) p(2)+0.3 p(3)])
            clear t p;
            axis equal;

            p = get(h, 'pos');
            p(1) = p(1)-0.014 ;
            p(2) = p(2)-0.05 ;
            p(3) = p(3)+0.01 ;
            p(4) = p(4)-0.1 ;
            set(h, 'pos', p);
            clear h p;

            h = subplot(2, nhmethods, j+nhmethods);
            p = get(h, 'pos');
            p(1) = p(1)-0.024 ;
            p(3) = p(3)+0.024 ;
            p(4) = p(4)+0.4 ;
            set(h, 'pos', p);
            clear p h;
            montage(I2(:, :, :, 2:param.numRetrieval+1));
            title(hashmethods{j});
        end
    case 'CALTECH256CNN'
        load 256CNN1024dNorml.mat;
        allNames = rgbImgList';
        %allmgs = dir('256_ObjectCategories');
        %allNames = {allmgs(~[allmgs.isdir]).name};
        %figure('Color', [1 1 1]); hold on;
        for j = 1: nhmethods
            I2 = uint8(zeros(100, 103, 3, 26)); % 32 and 32 are the size of the output image
            for i=1:(param.numRetrieval+1)
                index = retrieval_list{1, j}(i,1);
                imName_path=['J:\database\256_ObjectCategories\', allNames{1, index}];
                %imName_path=['256_ObjectCategories/', allNames{1, index}];
                im = imread(imName_path);
                im = imresize(im, [100 100]);
                if (ndims(im)~=3)
                    I2(1:100, 1:100, 1, i) = im;
                    I2(1:100, 1:100, 2, i) = im;
                    I2(1:100, 1:100, 3, i) = im; 
                else
                    I2(1:100, 1:100, :, i) = im;
                end
            end

            % show form 1
            figure('Color', [1 1 1]);
            queryIm = I2(1:100, 1:100, :, 1);
            imshow(queryIm);
            title('Query image');

            figure('Color', [1 1 1]);

            subplot(5,1,1)
            montage(I2(:, :, :, 2:6), 'Size', [1 NaN]);
            title(hashmethods{j});
            subplot(5,1,2)
            montage(I2(:, :, :, 7:11), 'Size', [1 NaN]);
            subplot(5,1,3)
            montage(I2(:, :, :, 12:16), 'Size', [1 NaN]);
            subplot(5,1,4)
            montage(I2(:, :, :, 17:21), 'Size', [1 NaN]);
            subplot(5,1,5)
            montage(I2(:, :, :, 22:param.numRetrieval+1), 'Size', [1 NaN]);

            % show form 2
            %h =subplot(2, nhmethods, j);
            %queryIm = I2(:, :, :, 1);
            %imshow(queryIm);
            %t = title('Query image');
            %p = get(t,'Position');
            %set(t,'Position',[p(1) p(2)+0.3 p(3)])
            %clear t p;
            %axis equal;

            %p = get(h, 'pos');
            %p(1) = p(1)-0.014 ;
            %p(2) = p(2)-0.05 ;
            %p(3) = p(3)+0.01 ;
            %p(4) = p(4)-0.1 ;
            %set(h, 'pos', p);
            %clear h p;

            %h = subplot(2, nhmethods, j+nhmethods);
            %p = get(h, 'pos');
            %p(1) = p(1)-0.024 ;
            %p(3) = p(3)+0.024 ;
            %p(4) = p(4)+0.4 ;
            %set(h, 'pos', p);
            %clear p h;
            %montage(I2(:, :, :, 2:param.numRetrieval+1));
            %title(hashmethods{j});
        end
end

稍微调整一下就可以用了。

xysoul commented 8 years ago

非常感谢!~ 另外,在后面的评价时,有监督的采用的groundtruth是真实的类标记,您说这里采用的是原空间测试样本的最近邻定义的groundtruth,那它们是否有可比性呢?还是不太明白,如果想要加入新的算法需要改动哪些地方

willard-yuan commented 8 years ago

@keepmovingXY groundtruth是人为定的,既可以采用真实的类标记,也可以用最近邻做为groundtruth。不过对于这两种评价指标的选择,你如果想选择对自己方法有利的评价方式,你需要看你的方法是Semantic Similarity还是Euclidean Similarity方法,如果是Euclidean Similarity类别的方法,那肯定选用最近邻定义的groundtruth对你的方法是有利的。

willard-yuan commented 8 years ago

另外有时间的话,在这一段时间我会把结构更合理的新版本推送上去,快毕业了,哈哈

xysoul commented 8 years ago

@willard-yuan 好棒~毕业快乐~ 学长您后来也一直在研究这个吗?可以加你好友吗?

willard-yuan commented 8 years ago

是的,主要研究这个,不过不限于这个,还有涉及图像检索的其他方法,可以加我微信Willardyy。

xysoul commented 8 years ago

@willard-yuan 加你啦~
小胖子

xysoul commented 8 years ago

学长,想请教一下,这个程序中的关于精确度和召回率等的计算是单纯根据原空间测试样本的最近邻定义的groundtruth来的,能否根据传入一张给定的图片计算精确度呢?如果要计算某一个算法的running time,是否也应该是计算传入图片到检索结束的时间呢?

willard-yuan commented 8 years ago

@xysoul 这个代码里面计算查准率和查全率是根据每一幅图像的查准率和查全率然后取的平均,所以你的这个也是可以做的。另外在哈希方法里,看某个方法的时间,文献中比较的都是训练时间和测试时间,所以你只需要在训练代码的开始部分和结束部分加个时间计算的过程即可。