Grey Image Colorization using deep learning

5 次查看(过去 30 天)
Hello, I'm trying to colorize an grey image using Matlab. there is multiple example in pyhton etc. I can't find any example in mathlab. I'm sharing the codes I got until today.
When training is over I got a little colored images but mostly yelow. And traning progress down below as an image. Can you tell me how can I read this graph? How can I understant it's fail or still learning ?
What should I do ? Some examples using Lab colorstyle instead of RGB. How can I train using Lab?
And I want to learn this codes meanings :
miniBatchSize = 16;
patchSize = [250 250];
patchds = randomPatchExtractionDatastore(greyimds,Trainimds,patchSize, ....
'PatchesPerImage',64);
patchds.MiniBatchSize = miniBatchSize;
When I scale up miniBatchSize my training fail because of GPU. Why?
When I scale up encoderDepth, traning can't work because it's ask for 2*Image height/width or something like that? How can I calculate it ? What it's means?
lgraph = unetLayers([250 250 3] , 3,'encoderDepth',1);
And last question: How can I get score of tranings success rate? I try some codes but they don't let me because it's not a classification problem.
Thanks for everything.
imagesDir = '.';
greyImagesDir = fullfile(imagesDir,'greyImages');
trainImagesDir = fullfile(imagesDir,'trainImages');
exts = {'.jpg','.bmp','.png'};
greyimds = imageDatastore(blurredImagesDir)
Trainimds = imageDatastore(trainImagesDir)
miniBatchSize = 16;
patchSize = [250 250];
patchds = randomPatchExtractionDatastore(greyimds,Trainimds,patchSize, ....
'PatchesPerImage',64);
patchds.MiniBatchSize = miniBatchSize;
lgraph = unetLayers([250 250 3] , 3,'encoderDepth',1);
lgraph = lgraph.removeLayers('Softmax-Layer');
lgraph = lgraph.removeLayers('Segmentation-Layer');
lgraph = lgraph.addLayers(regressionLayer('name','regressionLayer'));
lgraph = lgraph.connectLayers('Final-ConvolutionLayer','regressionLayer');
maxEpochs = 30;
epochIntervals = 1;
initLearningRate = 0.1;
learningRateFactor = 0.1;
l2reg = 0.0001;
options = trainingOptions('sgdm', ...
'Momentum',0.9, ...
'InitialLearnRate',initLearningRate, ...
'LearnRateSchedule','piecewise', ...
'LearnRateDropPeriod',10, ...
'LearnRateDropFactor',learningRateFactor, ...
'L2Regularization',l2reg, ...
'MaxEpochs',maxEpochs ,...
'MiniBatchSize',miniBatchSize, ...
'GradientThresholdMethod','l2norm', ...
'Plots','training-progress', ...
'GradientThreshold',0.01);
modelDateTime = datestr(now,'dd-mmm-yyyy-HH-MM-SS');
net = trainNetwork(patchds,lgraph,options);
save(['trainedNet-' modelDateTime '-Epoch-' num2str(maxEpochs*epochIntervals) ...
'ScaleFactors-' num2str(234) '.mat'],'net','options');
------------------Colorize image using code below---
Idegray = activations(net,testimage,'regressionLayer');
figure; imshow(Idegrey)
Iapprox = rescale(Idegrey);
Iapprox = im2uint8(Iapprox);
imshow(Iapprox)
title('Colored Image')

采纳的回答

Tolga Arslan
Tolga Arslan 2019-7-12
编辑:Tolga Arslan 2019-7-12
I found answer of EncoderDepth problem :
Network input image size, specified as a:
2-element vector in the format [height, width].
3-element vector in the format [height, width, depth]. depth is the number of image channels. Set depth to 3 for RGB images, 1 for grayscale images, or to the number of channels for multispectral and hyperspectral images.
Note
Each encoder section has a 2x2 maxPooling2dLayer that halves the image size. The height and width of the input image must be a multiple of 2D, where D is the value of EncoderDepth.
If I understant true : I'm working with 250x250 image size. I have to use 3 for EncoderDepth, My input can gray scale but output is RGB. If I make it 3, 2³ =8 250/8 : 31,25. It's mean fails. I have to setup by image sizes 256x256.
Please comment if I understant correctly this situation. I will try and let you know asap.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Deep Learning for Image Processing 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by