-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtest.m
64 lines (57 loc) · 1.83 KB
/
test.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
56
57
58
59
60
61
62
63
64
clc;clear;close all;
inpath='/home/wang/Documents/datasets/datasets/ECCSD/';
outpath='./ECSSD_FX/';
mkdir(outpath);
in_dir=dir(inpath);
imgnum=length(in_dir);
%
% addpath(genpath('/home/wujie/caffe-master/matlab'));
addpath(genpath('/home/wang/Desktop/PSPNet-master/matlab'));
net_model='./deploy.prototxt';
net_weights='./caffemodel/FXResnet_iter_300000.caffemodel';
phase='test';
caffe.set_mode_gpu();
caffe.set_device(0);
% Initialize a network
net=caffe.Net(net_model, net_weights, phase);
IMAGE_DIM = 353;
for i=1:imgnum-2
i
imgname=in_dir(i+2).name;
img_name=[inpath imgname];
out_name=[outpath imgname(1:end-4) '.png'];
% if ~exist(out_name)
im=imread(img_name);
% resize to fixed input size
im = single(im);
[m n k]=size(im);
% mean BGR pixel
% mean_pix = [104.00699, 116.66877, 122.67892];
mean_pix=[0 0 0];
im = imresize(im, [IMAGE_DIM IMAGE_DIM]);
% RGB -> BGR
im = im(:, :, [3 2 1]);
% oversample (4 corners, center, and their x-axis flips)
images = zeros(IMAGE_DIM, IMAGE_DIM, 3, 1, 'single');
images(:,:,1:3,1)=permute(im,[2 1 3]);
% mean BGR pixel subtraction
for c = 1:3
images(:, :, c, :) = images(:, :, c, :) - mean_pix(c);
end
input_data = {images};
% do forward pass to get scores
% scores are now Width x Height x (Channels x 2) x Num
% tic;
scores=net.forward(input_data);
%scores = caffe('forward', input_data);
% toc;
temp=scores{1}(:,:,2);
map=permute(temp,[2,1,3]);
% map(map<0)=0;
% map=double(medfilt2(map,[8,8]));
map=imresize(map,[m,n]);
map=(map-min(map(:)))./(max(map(:))-min(map(:)));
% map=uint8(map*255);
imwrite(map,out_name,'png');
% end
end