-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathV_inpaint.m
60 lines (47 loc) · 1.53 KB
/
V_inpaint.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
% only work for matconvet now
param_init
% parameters to set
TOPIC_ID=2;
mn='alex';ln='f7'; % fc7
cnn_mode='matconvnet'; % 'caffe' or 'matconvnet'
neuron_rand=1;
init_sz = [227 227 3];
% 1. load model
% cat example
% load model
opts.task = 2;opts.objective = 'oneclass';
if ~exist('net','var');U_loadModel;end
classId = 333;oldClassName='cat';
opts.dsp = 5;
opts.do_thres=1;
load(['data/inpaint/locate_' oldClassName],'mask_rm','im0','p5_mask')
% choose a class
opts.mask=zeros(1,1000,'single');
opts.mask(classId)=1;
% choose a pool5
tmp_p5 = imdilate(p5_mask,strel('disk',1));
tmp_p5(3,3)=0;
%tmp_p5 = p5_mask;
opts.fmask = {};
% choose a fc7 topic
topic= load(sprintf('data/fc7-topic/%d.mat',classId-1));
opts.fmask={{16,repmat(tmp_p5,[1,1,256])},{20,reshape(topic.W(:,TOPIC_ID)>1,[1,1,4096])}};
% region to modify
% hand tune...
opts.xmask = single(zeros(init_sz));
bb=[45 150 60 180];
opts.xmask(bb(1):bb(2),bb(3):bb(4),:) = 1;
init_pb = single(imread(['data/inpaint/locate_' oldClassName '.png']));
% initial image/db
%im_init = U_prepare_image(init_pb,[],1,1);
im_init = bsxfun(@minus,init_pb,reshape([103.939, 116.779, 123.68],[1,1,3]));
% pm-init
r_std=20;
opts.init = U_init_r(im_init,opts.xmask,r_std,im_init);
% 2.3 optization parameters
opts= U_param(opts,mn,ln); % hard-coded learning rate and MRF energy parameters
% same order with the fc term
exp = experiment_init(mn, [], '', 'cnn', opts) ;
res = experiment_run(exp,net);
im0 = uint8(res.output{end});
%imwrite(im0,[DD_out sprintf('ip_%s_%d_%d_%d_%d.png',nn,tid,doid,TOPIC_ID,doid3)])