forked from phoenix104104/LapSRN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
train_LapSRN.m
67 lines (56 loc) · 2.11 KB
/
train_LapSRN.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
65
66
function train_LapSRN(scale, depth, gpu)
% -------------------------------------------------------------------------
% Description:
% Script to train LapSRN from scratch
%
% Input:
% - scale : SR upsampling scale
% - depth : numbers of conv layers in each pyramid level
% - gpu : GPU ID, 0 for CPU mode
%
% Citation:
% Deep Laplacian Pyramid Networks for Fast and Accurate Super-Resolution
% Wei-Sheng Lai, Jia-Bin Huang, Narendra Ahuja, and Ming-Hsuan Yang
% IEEE Conference on Computer Vision and Pattern Recognition (CVPR), 2017
%
% Contact:
% Wei-Sheng Lai
% University of California, Merced
% -------------------------------------------------------------------------
%% initialize opts
opts = init_opts(scale, depth, gpu);
%% save opts
filename = fullfile(opts.train.expDir, 'opts.mat');
fprintf('Save parameter %s\n', filename);
save(filename, 'opts');
%% setup paths
addpath(genpath('utils'));
addpath(fullfile(pwd, 'matconvnet/matlab'));
vl_setupnn;
%% initialize network
fprintf('Initialize network...\n');
model_filename = fullfile(opts.train.expDir, 'net-epoch-0.mat');
if( ~exist(model_filename, 'file') )
model = init_LapSRN(opts);
fprintf('Save %s\n', model_filename);
net = model.saveobj();
save(model_filename, 'net');
else
fprintf('Load %s\n', model_filename);
model = load(model_filename);
model = dagnn.DagNN.loadobj(model.net);
end
%% load imdb
imdb_filename = fullfile('imdb', sprintf('imdb_%s.mat', opts.data_name));
if( ~exist(imdb_filename, 'file') )
make_imdb(imdb_filename, opts);
end
fprintf('Load data %s\n', imdb_filename);
imdb = load(imdb_filename);
fprintf('Pre-load all images...\n');
imdb.images.img = batch_imread(imdb.images.filename);
%% training
get_batch = @(x,y,mode) getBatch_LapSRN(opts,x,y,mode);
[net, info] = vllab_cnn_train_dag(model, imdb, get_batch, opts.train, ...
'val', find(imdb.images.set == 2));