forked from willard-yuan/cnn-for-image-retrieval
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathextractCNN.m
More file actions
73 lines (57 loc) · 1.92 KB
/
extractCNN.m
File metadata and controls
73 lines (57 loc) · 1.92 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
% Author: Yong Yuan
% Homepage: yongyuan.name
clear all;close all;clc;
% version: matconvnet-1.0-beta10
%run ./matconvnet-1.0-beta10/matlab/vl_setupnn
% version: matconvnet-1.0-beta12
%run ./matconvnet-1.0-beta12/matlab/vl_setupnn
% version: matconvnet-1.0-beta14,ÍÆ¼öʹÓÃ
run ./matconvnet-1.0-beta14/matlab/vl_setupnn
%% Step 1 lOADING PATHS
path_imgDB = './database/';
addpath(path_imgDB);
addpath tools;
% viesion: matconvnet-1.0-beta10
%net = load('I:/imagenetMat/imagenet-vgg-f.mat') ;
% viesion: matconvnet-1.0-beta12
net = load('I:/imagenetMat/imagenet-vgg-f.mat') ;
%% Step 2 LOADING IMAGE AND EXTRACTING FEATURE
imgFiles = dir(path_imgDB);
imgNamList = {imgFiles(~[imgFiles.isdir]).name};
clear imgFiles;
imgNamList = imgNamList';
numImg = length(imgNamList);
feat = [];
rgbImgList = {};
%parpool;
%parfor i = 1:numImg
for i = 1:numImg
oriImg = imread(imgNamList{i, 1});
if size(oriImg, 3) == 3
im_ = single(oriImg) ; % note: 255 range
im_ = imresize(im_, net.normalization.imageSize(1:2)) ;
im_ = im_ - net.normalization.averageImage ;
res = vl_simplenn(net, im_) ;
% viesion: matconvnet-1.0-beta10
%featVec = res(19).x;
% viesion: matconvnet-1.0-beta12
featVec = res(20).x;
featVec = featVec(:);
feat = [feat; featVec'];
fprintf('extract %d image\n\n', i);
else
im_ = single(repmat(oriImg,[1 1 3])) ; % note: 255 range
im_ = imresize(im_, net.normalization.imageSize(1:2)) ;
im_ = im_ - net.normalization.averageImage ;
res = vl_simplenn(net, im_) ;
% viesion: matconvnet-1.0-beta10
%featVec = res(19).x;
% viesion: matconvnet-1.0-beta12
featVec = res(20).x;
featVec = featVec(:);
feat = [feat; featVec'];
fprintf('extract %d image\n\n', i);
end
end
feat_norm = normalize1(feat);
save('feat4096Norml.mat','feat_norm', 'imgNamList', '-v7.3');