forked from omrysendik/DCor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGetLossFromImg.m
38 lines (30 loc) · 1.83 KB
/
GetLossFromImg.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
function [errorLoss] = GetLossFromImg(net,curTgtImg,SrcImg,srcMats,params)
global SavedDataPrevErrors;
global SavedDataPrevDeltas;
global SavedDataPrevImg;
if(params.lbfgs_opts.autoconverge==1 && numel(SavedDataPrevDeltas)>=params.lbfgs_opts.autoconvergelen+1)
if(prod(SavedDataPrevDeltas(end-params.lbfgs_opts.autoconvergelen:end)<=params.lbfgs_opts.autoconvergethresh))
errorLoss = 0;
disp('Auto Converge');
return;
end
end
curTgtImg = reshape(curTgtImg,[round(params.USFac*size(SrcImg,1)),round(params.USFac*size(SrcImg,2)),size(SrcImg,3)]);
[tgtFeatures.styleFeatures, tgtFeatures.ACorrFeatures, tgtFeatures.DiversityFeatures, tgtFeatures.SmoothnessFeatures] = CalcNetFeatures(net, curTgtImg, params);
[errorLoss] = CalcErrorLoss(srcMats,tgtFeatures,params, 1);
disp(['Total Loss=',num2str(errorLoss)]);
if(~isempty(SavedDataPrevImg))
CurrMaxPixDiff = max(abs(SavedDataPrevImg(:)-curTgtImg(:)));
else
CurrMaxPixDiff = 0;
end
SavedDataPrevErrors = [SavedDataPrevErrors errorLoss];
SavedDataPrevDeltas = [SavedDataPrevDeltas CurrMaxPixDiff];
SavedDataPrevImg = curTgtImg;
figure(100);
subplot(2,2,1); imshow(uint8(ImDenorm(curTgtImg,net.meta.normalization.averageImage))); title('Result');
subplot(2,2,2); imshow(uint8(ImDenorm(SrcImg,net.meta.normalization.averageImage))); title('Input');
subplot(2,2,3); plot(1:numel(SavedDataPrevErrors),log10(SavedDataPrevErrors+1)); title('Error');
subplot(2,2,4); plot(1:numel(SavedDataPrevDeltas),SavedDataPrevDeltas); title('Max Pixel Diffs'); ylim([0 30]);
drawnow
save([params.OutString,'__CurTgtImg.mat'],'curTgtImg');