try to implement the image to image regression using CAE but except digit dataset its not working for any other dataset. thank you.
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
this is the code code :https://in.mathworks.com/help/deeplearning/ug/image-to-image-regression-using-deep-learning.html
only the dataset has changed but output is not shown .
clc;
clear all;
close all;
imagefile=fullfile('C:\Users\dibya\Documents\images\kodak');
imds=imageDatastore(imagefile,...
'IncludeSubfolders',true,...
'LabelSource','Foldernames')
imds.ReadSize = 70;
rng(0);
imds = shuffle(imds);
[imdsTrain,imdsVal,imdsTest] = splitEachLabel(imds,0.8,0.1);
dsTrainNoisy = transform(imdsTrain,@addNoise);
dsValNoisy = transform(imdsVal,@addNoise);
dsTestNoisy = transform(imdsTest,@addNoise);
dsTrain = combine(dsTrainNoisy,imdsTrain);
dsVal = combine(dsValNoisy,imdsVal);
dsTest = combine(dsTestNoisy,imdsTest);
dsTrain = transform(dsTrain,@commonPreprocessing);
dsVal = transform(dsVal,@commonPreprocessing);
dsTest = transform(dsTest,@commonPreprocessing);
dsTrain = transform(dsTrain,@augmentImages);
exampleData = preview(dsTrain);
inputs = exampleData(:,1);
responses = exampleData(:,2);
minibatch = cat(2,inputs,responses);
montage(minibatch','Size',[8 2])
title('Inputs (Left) and Responses (Right)')
imageLayer = imageInputLayer([32,32,1]);
encodingLayers = [ ...
convolution2dLayer(3,16,'Padding','same'), ...
reluLayer, ...
maxPooling2dLayer(2,'Padding','same','Stride',2), ...
convolution2dLayer(3,8,'Padding','same'), ...
reluLayer, ...
maxPooling2dLayer(2,'Padding','same','Stride',2), ...
convolution2dLayer(3,8,'Padding','same'), ...
reluLayer, ...
maxPooling2dLayer(2,'Padding','same','Stride',2)];
% % % % % % % % % % Decoder
decodingLayers = [ ...
createUpsampleTransponseConvLayer(2,8), ...
reluLayer, ...
createUpsampleTransponseConvLayer(2,8), ...
reluLayer, ...
createUpsampleTransponseConvLayer(2,16), ...
reluLayer, ...
convolution2dLayer(3,1,'Padding','same'), ...
clippedReluLayer(1.0), ...
regressionLayer];
layers = [imageLayer,encodingLayers,decodingLayers];
% % % % training
options = trainingOptions('adam', ...
'MaxEpochs',100, ...
'MiniBatchSize',imds.ReadSize, ...
'ValidationData',dsVal, ...
'Shuffle','never', ...
'Plots','training-progress', ...
'Verbose',false);
net = trainNetwork(dsTrain,layers,options);
ypred = predict(net,dsTest);
inputImageExamples = preview(dsTest);
montage({inputImageExamples{1},ypred(:,:,:,1)});
ref = inputImageExamples{1,2};
originalNoisyImage = inputImageExamples{1,1};
psnrNoisy = psnr(originalNoisyImage,ref)
psnrDenoised = psnr(ypred(:,:,:,1),ref)
%
%
% % % % % % % % % % helping function
function dataOut = addNoise(data)
dataOut = data;
for idx = 1:size(data,1)
dataOut{idx} = imnoise(data{idx},'salt & pepper');
end
end
function dataOut = commonPreprocessing(data)
dataOut = cell(size(data));
for col = 1:size(data,2)
for idx = 1:size(data,1)
temp = single(data{idx,col});
temp = imresize(temp,[32,32]);
temp = rescale(temp);
dataOut{idx,col} = temp;
end
end
end
function dataOut = augmentImages(data)
dataOut = cell(size(data));
for idx = 1:size(data,1)
rot90Val = randi(4,1,1)-1;
dataOut(idx,:) = {rot90(data{idx,1},rot90Val),rot90(data{idx,2},rot90Val)};
end
end
function out = createUpsampleTransponseConvLayer(factor,numFilters)
filterSize = 2*factor - mod(factor,2);
cropping = (factor-mod(factor,2))/2;
numChannels = 1;
out = transposedConv2dLayer(filterSize,numFilters, ...
'NumChannels',numChannels,'Stride',factor,'Cropping',cropping);
end
0 commentaires
Réponses (0)
Voir également
Catégories
En savoir plus sur Image Processing and Computer Vision dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!