Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
86 changed files
with
1,707 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
function X = LoadSolver(folder, solver_file, mat_file) | ||
|
||
if exist(mat_file,'file') && ~isempty(mat_file) | ||
M_ = load(mat_file); | ||
X = T2_SolverParser(solver_file, M_); % TODO: save G_ | ||
else | ||
X = T2_SolverParser(solver_file); | ||
end | ||
|
||
if isfield(X,'snapshot_prefix') && exist('M_','var') | ||
[~,pr] = fileparts(X.snapshot_prefix); | ||
if isfield(X, 'iter') | ||
% saved path | ||
state = fullfile(folder, [pr,sprintf('_iter_%d.solverstate', X.iter)]); | ||
% tmp path | ||
X.state_file = [X.snapshot_prefix,sprintf('_iter_%d.solverstate', X.iter)]; | ||
copyfile(state, X.state_file); | ||
% saved path | ||
modes = fullfile(folder, [pr,sprintf('_iter_%d.caffemodel', X.iter)]); | ||
% tmp path | ||
X.model_file = [X.snapshot_prefix, sprintf('_iter_%d.caffemodel', Solver.G.iter)]; | ||
copyfile(modes, X.model_file); | ||
end | ||
else | ||
% dump existing models if there is no solver mat info | ||
delete(fullfile(folder, [pr,'*'])); | ||
X.state_file = []; | ||
fprintf('ALERT: please copy the pretrained caffemodel to %s.\n', X.model_file); | ||
end | ||
|
||
X = SR_init02(X, solver_file); | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
%º¯Êý¶¨Òå | ||
function y=RealGWbal(Image) | ||
Image=double(Image); | ||
r=Image(:,:,1); | ||
g=Image(:,:,2); | ||
b=Image(:,:,3); | ||
[x,y]=size(r); | ||
avgR = mean(r(:)); | ||
avgG = mean(g(:)); | ||
avgB = mean(b(:)); | ||
avgRGB = [avgR avgG avgB]; | ||
grayValue = (avgR + avgG + avgB)/3 ; | ||
scaleValue = grayValue./(avgRGB+0.001); | ||
R = scaleValue(1) * r; | ||
G = scaleValue(2) * g; | ||
B = scaleValue(3) * b; | ||
for i=1:x | ||
for j=1:y | ||
if(R(i,j)>255) | ||
R(i,j)=255; | ||
end | ||
if(G(i,j)>255) | ||
G(i,j)=255; | ||
end | ||
if(B(i,j)>255) | ||
B(i,j)=255; | ||
end | ||
end | ||
end | ||
% maxB=max(B(:)); | ||
newI(:,:,1)=R; | ||
newI(:,:,2)=G; | ||
newI(:,:,3)=B; | ||
y=newI; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
% parse all fields of a solver proto | ||
% transfer all FC layers in the existing model to CONV layers (equvelent) | ||
function [ Solver ] = SolverParser( solver_def_file, resume_file ) | ||
if ~exist(solver_def_file,'file')||isempty(solver_def_file) | ||
error('Solver definition file %s is not found.',solver_def_file); | ||
end | ||
if ~exist('resume_file','var') | ||
fprintf('Creating a face lmk solver structure based on %s.', solver_def_file); | ||
Solver = []; | ||
else | ||
load(resume_file); | ||
end | ||
fout = fopen(solver_def_file,'r'); | ||
tline = fgetl(fout); | ||
while ischar(tline) | ||
disp(tline) | ||
pos = 1; | ||
while tline(pos)==' ' | ||
pos = pos + 1; | ||
end | ||
if tline(pos) == '#' | ||
tline = fgetl(fout); | ||
continue; | ||
end | ||
ind = find(tline == '"',1); | ||
if ~isempty(ind) | ||
field = tline(ind + 1 : end - 1); | ||
ind2 = find(tline == ':',1); | ||
name = tline(1:ind2-1); | ||
else | ||
ind2 = find(tline == ':',1); | ||
if isempty(ind2) | ||
error('incorrect format.') | ||
end | ||
ctr = tline(ind2+2:end); | ||
if isempty(str2num(ctr)) | ||
ctr(isspace(ctr)) = []; | ||
field = ctr; | ||
else | ||
field = str2double(ctr); | ||
end | ||
name = tline(1:ind2-1); | ||
end | ||
Solver = setfield(Solver, name, field); | ||
tline = fgetl(fout); | ||
end | ||
fclose(fout); | ||
if ~isfield(Solver, 'solver_mode') | ||
Solver.solver_mode = 'GPU'; | ||
end | ||
if ~isfield(Solver, 'device_id') && strcmp(Solver.solver_mode, 'GPU') | ||
Solver.device_id = 0; | ||
end | ||
if isfield(Solver,'model') | ||
lnum = length(Solver.model); | ||
for ind = 1:lnum | ||
if strcmp(Solver.model(ind).layer_names,sprintf('fc%d',ind)) | ||
Solver.model(ind).layer_names = sprintf('conv%d',ind); | ||
weights = Solver.model(ind).weights{1}; | ||
[s1,s2] = size(weights); | ||
[~,~,~,ch] = size(Solver.model(ind-1).weights{1}); | ||
filtersize = sqrt(s1/ch); | ||
weights = reshape(weights,[filtersize,filtersize,ch,s2]); | ||
Solver.model(ind).weights{1} = weights; | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
function X = caffe_init(X, solver_file) | ||
|
||
if ~exist(solver_file,'file') || isempty(solver_file) | ||
error('You need a solver prototxt definition.') | ||
end | ||
X.Solver_ = caffe.Solver(solver_file); % to cpp | ||
if isfield(X, 'state_file') && ~isempty(X.state_file) && exist(X.state_file, 'file') | ||
X.Solver_.restore(X.state_file); | ||
fprintf('resume from snapshot file %s...\n', X.state_file); | ||
elseif isfield(X, 'model_file') && ~isempty(X.model_file) | ||
X.Solver_.net.copy_from(X.model_file); | ||
fprintf('resume from caffemodel file %s...\n', X.model_file); | ||
end | ||
|
||
% set caffe mode | ||
if strcmp(X.solver_mode,'GPU') | ||
caffe.set_mode_gpu(); | ||
caffe.set_device(X.device_id); | ||
else | ||
caffe.set_mode_cpu(); | ||
end | ||
fprintf('Done with init %s\n', solver_file); | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
% DEMO_TEST.m | ||
|
||
addpath(genpath('/home/vision/wren/caffe-dilate')); | ||
caffe.reset_all(); | ||
clc; clear; | ||
|
||
hazy_path = ('./inputs/'); | ||
type = '*.png'; | ||
hazy_data = dir(fullfile(hazy_path,type)); | ||
|
||
model_path = './models/'; | ||
|
||
solver_file = fullfile(model_path, 'dehaze_solver_test.prototxt'); | ||
save_file = fullfile(model_path, 'dehaze_ps128_bs1.mat'); | ||
|
||
Solver = modelconfig_test( solver_file, save_file); | ||
% Solver.iter | ||
Solver.batchsize = 1; | ||
for ii = 45:length(hazy_data) | ||
disp(ii) | ||
clear batch; | ||
hazyimg = im2double(imread(fullfile(hazy_path,hazy_data(ii).name))); | ||
|
||
[row, col, cha] = size(hazyimg); | ||
|
||
% resize the input to a multiple of 8 | ||
height = ceil(row/8)*8; | ||
width = ceil(col/8)*8; | ||
hazyimg = imresize(hazyimg, [height, width]); | ||
|
||
|
||
hazy_wb = RealGWbal(uint8(255*hazyimg)); | ||
hazy_wb = hazy_wb/255; | ||
hazy_cont = (2*(0.5+mean(hazyimg(:)))).*(hazyimg-mean(hazyimg(:))); | ||
hazy_gamma = hazyimg.^2.5; | ||
|
||
batch(:,:,1:3) = hazyimg; | ||
batch(:,:,4:6) = hazy_wb; | ||
batch(:,:,7:9) = hazy_cont; | ||
batch(:,:,10:12) = hazy_gamma; | ||
|
||
% figure(1);subplot(221), imshow(hazyimg);subplot(222),imshow(hazy_wb); | ||
% subplot(223), imshow(hazy_cont); subplot(224),imshow(hazy_gamma); | ||
|
||
batchc = {single(batch)}; | ||
|
||
Solver.Solver_.net.blobs('data').reshape([height, width, 12, 1]); | ||
|
||
tic | ||
activec = Solver.Solver_.net.forward(batchc); | ||
toc | ||
dehazed= activec{3}; | ||
|
||
% dehazed = imresize(dehazed, [size(TEST_IMAGE, 1), size(TEST_IMAGE, 2)]); | ||
|
||
imwrite(dehazed, strcat('./results/',hazy_data(ii).name(1:end-4),'_dehazed.png')); | ||
end | ||
%imshow(out);title('Original/Proposed/GT'); | ||
%weights=Solver.Solver_.net.get_weights(); | ||
%data=Solver.Solver_.net.get_data(); | ||
%diff=Solver.Solver_.net.get_diff(); |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
function Solver = modelconfig_test(solver_file, save_file) | ||
|
||
if exist(save_file, 'file') | ||
% M_ = load(save_file); | ||
% fprintf('loading saved model.\n'); | ||
Solver = SolverParser(solver_file, save_file); | ||
else | ||
Solver = SolverParser(solver_file); | ||
end | ||
|
||
Solver.iter = 240000; | ||
|
||
if isfield(Solver, 'snapshot_prefix') | ||
if isfield(Solver, 'iter') | ||
Solver.state_file = [Solver.snapshot_prefix,sprintf('_iter_%d.solverstate', Solver.iter)]; | ||
Solver.model_file = [Solver.snapshot_prefix, sprintf('_iter_%d.caffemodel', Solver.iter)]; | ||
else | ||
Solver.state_file = []; | ||
fprintf('ALERT: no pretrained snapshot found.\n'); | ||
end | ||
end | ||
|
||
Solver = caffe_init(Solver, solver_file); | ||
Solver.matfile = save_file; | ||
% Solver.state_path = state_path; | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
net: "models/multi_fusion_test.prototxt" | ||
test_iter: 20 | ||
test_interval: 500 | ||
base_lr: 0.0001 | ||
momentum: 0.9 | ||
momentum2: 0.999 | ||
weight_decay: 0.00001 | ||
solver_type: ADAM | ||
lr_policy: "poly" | ||
clip_gradients: 80 | ||
power: 2 | ||
gamma: 0.1 | ||
stepsize: 20000 | ||
display: 10 | ||
max_iter: 100000 | ||
snapshot: 10000 | ||
snapshot_prefix: "./models/snapshot/" | ||
solver_mode: CPU | ||
device_id: 0 |
Oops, something went wrong.