layumi / 2016_super_resolution

ICCV2015 Image Super-Resolution Using Deep Convolutional Networks
MIT License
86 stars 43 forks source link

I have a problem after I trained your sample images, which you did upload in baidu. #4

Open star4s opened 7 years ago

star4s commented 7 years ago

Hello. I have a problem after I trained your sample images, which you did upload in baidu. And I apply the mat file in your testSRnet_result.m after the training and, I also apply the mat file, your 2014_data_url_onlycolor.mat. After I run the testSRnet_result.m, I got the strange result like the bottom. left: original image , right: SR image 1

However, when I apply your mat file for the training, it works well. I think I got the problem in my image training. Thank you for your attention.

layumi commented 7 years ago

@star4s Do you change any training code?
The result seems like only show the green channel.

star4s commented 7 years ago

I did not change your code. I just use your code on the page. What's the problem? I did not know the situation.

layumi commented 7 years ago

@star4s There may be several things you need to check:

  1. Do you show the result in a right way? Does the third channel of the output equal to 3? (for example 224x224x3) If the scale of the image are in the range 1 to 256, the format of the img should be 'uint8'. uint8(img) If the image are in the range 0 to 1, it should be 'single'. single(img)

  2. Visualize the training images you downloaded. Are they right?

star4s commented 7 years ago
  1. Yes, the result of the image is 656 988 3 single.

  2. This is your the training images. 1

This is a result graph after I train from your images. When I compared your result graph, the result is very different. 2

layumi commented 7 years ago

Do you use %im_1 = rgb2ycbcr(im_1); ? Actually I do not use it and comment it.

star4s commented 7 years ago

I tried again by using same option for training images. I have different color result. I do not know why the result is strange. 3

star4s commented 7 years ago

This is my code from your code train_SRnet.m could you check what the problem is?

function train_SRnet(varargin) addpath('C:\Program Files\MATLAB'); % ------------------------------------------------------------------------- % Part 4.1: prepare the data % -------------------------------------------------------------------------

% Load character dataset imdb = load('./2014_data_url_onlycolor.mat') ; imdb = imdb.imdb; imdb.meta.sets=['train','val']; ss = size(imdb.images.data); imdb.images.set = ones(1,ss(2)); imdb.images.set(ceil(rand(1,ceil(ss(2)/20))*ss(2))) = 2; % ------------------------------------------------------------------------- % Part 4.2: initialize a CNN architecture % -------------------------------------------------------------------------

net = SRnet(); net.conserveMemory = true; %net = load('data/48net-cifar-v3-custom-dither0.1-128-3hard/f48net-cpu.mat');

% ------------------------------------------------------------------------- % Part 4.3: train and evaluate the CNN % -------------------------------------------------------------------------

opts.train.batchSize = 128; %opts.train.numSubBatches = 1 ; opts.train.continue = true; opts.train.gpus = 1; opts.train.prefetch = false ; %opts.train.sync = false ; %opts.train.errorFunction = 'multiclass' ; opts.train.expDir = './data/SRnet-v1-color-128_new'; opts.train.learningRate = [1e-5ones(1,3) 1e-6ones(1,1)]; opts.train.weightDecay = 0.0005; opts.train.numEpochs = numel(opts.train.learningRate) ; opts.train.derOutputs = {'objective',1} ; [opts, ~] = vl_argparse(opts.train, varargin) ;

%record if(~isdir(opts.expDir)) mkdir(opts.expDir); copyfile('SRnet.m',opts.expDir); end

% Call training function in MatConvNet [net,info] = cnn_train_daga(net, imdb, @getBatch,opts) ;

% -------------------------------------------------------------------- function inputs = getBatch(imdb, batch,opts) % -------------------------------------------------------------------- imlist = imdb.images.data(:,batch) ; batch_size = numel(batch); img = zeros(128,128,3,batch_size,'single'); training = opts.learningRate>0; for i=1:batch_size p1 = imlist{i}; im_1 = imread(p1); %im_1 = rgb2ycbcr(im_1); %im_1 = rgb2gray(im_1);

im_1 = im2single(im_1);
im_1 = single(random_cut128(im_1));
img(:,:,:,i) = im_1;

end if(rand>0.5) img = fliplr(img); end label = img(7:end-6,7:end-6,:,:); [w,h,~,~] = size(img); r = 2 + 2*rand; input = imresize(imresize(img,1/r),[w,h]); inputs = {'input',gpuArray(input),'label',gpuArray(label)};

star4s commented 7 years ago

If you look at my code, train_SRnet.m, I did not use %im_1 = rgb2ycbcr(im_1); and %im_1 = rgb2gray(im_1); . I just input train_SRnet on the command line of the matlab.

layumi commented 7 years ago

add imshow(input(:,:,:,1)); before the inputs = {'input',gpuArray(input),'label',gpuArray(label)}; add breakpoint. Does it show right?

star4s commented 7 years ago

After I add breakpoint, there is the result.

4 6 7 5

And then, the result on the command line, there is text. 8

layumi commented 7 years ago

I think the input is right. The question may be in the training process. The training curve do not converge?? The loss seems keep high. Do you use my initial code? /matlab/+dagnn/@DagNN/initParam.m

star4s commented 7 years ago

What's mean? The curve do not converge?? I just used your code in the training process. I changed the option for count of the GPU. on your code, there is opts.train.gpus = 2; My gpu is 1. so I changed the option by 1. Like that, opts.train.gpus = 1;

And I did not changed your code.

star4s commented 7 years ago

my vl_compilenn 's option is just vl_compilenn('enableGpu', true); and then I can use GPU and Caffe.

star4s commented 7 years ago

I did not use initial code, /matlab/+dagnn/@DagNN/initParam.m How can I run the initial code? My processing was

  1. gpu_compile
  2. vl_compilenn('enableGpu', true);
  3. train_SRnet
layumi commented 7 years ago

I wrote this code one year ago and do not keep it in my computer. Let me download file and re-train my model to see whether there is any bugs. It may take some times. But I will try and tell you the result.

star4s commented 7 years ago

Thank you very much for your using time.

layumi commented 7 years ago

@star4s I found the bugs.

  1. I wrote the rmsprop but I used sgd optimizer. In theroy, rmsprop is better than sgd. But I found sgd can do better. So I forget to change it from rmsprop to sgd. It's my fault.
  2. I found it is beneficial to train the network by fixing the size scale 2. I wrote it in the readme.md but forget to change the getBatch function.

So I will upload a fixed version for training code today. And I will remove some unnecessary files to keep it more clear and simply to train.