MATLAB Answers

0

Creating a convolutional neural network that outputs an image.

Asked by Emir Semsic on 18 Jan 2019
Latest activity Commented on by Joss Knight
on 2 Feb 2019
I am in the process of implementing a convolutional neural network for image denoising. The network architecture was proposed in THIS paper, on page 4. I am using Matlab 2018b, so I have all the latest Deep learning toolboxes installed. I have tried to recreate the neural network in the Deep Network Designer app, as can be seen in the two first images attached. The network analyzer shows no errors or warning, and the dimensions are ok.
Then I created an imagedatastore with my images. The second step was creating an denoisingImageDatastore for the sake of training deep networks. I then set the training options, and eventually went to train my network. All these steps were show in Mathworks tutorials, but here is the code anyway.
DatasetPath=fullfile('c:\', 'Users', 'Emir', 'Desktop', 'IU','seminarski', 'VOCdevkit', 'VOC2010','JPEGImagesSmall');
imds=imageDatastore(DatasetPath, 'IncludeSubfolders', true,...
'LabelSource','foldernames');
%% denoising image data set
dnimds=denoisingImageDatastore(imds,'patchSize', [64 64], 'PatchesPerImage', 64, 'ChannelFormat','grayscale');
%%
options = trainingOptions('sgdm', ...
'InitialLearnRate',0.01, ...
'MaxEpochs',1, ...
'Shuffle','every-epoch', ...
'ValidationFrequency',30, ...
'Verbose',false, ...
'Plots','training-progress',...
'ExecutionEnvironment', 'gpu');
%%
net=trainNetwork(dnimds, lgraph_8,options); %% lgraph_8 is the name of the network returned by the deep network designer app
I then went to test my trained network on the cameraman image.
I=imread('cameraman.tif');
noisyI=imnoise(I, 'gaussian', 0,0.01);
figure
imshowpair(I, noisyI, 'montage');
title('Original Image (left) and Noisy Image (right)')
%%
denoisedI=denoiseImage(noisyI,net);
figure
imshow(denoisedI)
title('Denoised Image')
I get the following error message when running this script.
"Name of layer output must be a character vector or string scalar.
Error in DAGNetwork/activations (line 815)
iValidateIsStringOrCharArray(layerOut);
Error in denoiseImage (line 73)
res = activations(net,inputImage,numLayers-1,'OutputAs','channels');
Error in Untitled (line 44)
denoisedI=denoiseImage(noisyI,net);"
What causes this error message? In the proposed network, the output is an image of the dimensions 64x64x1, however it seems that matlab only lets me use the classification and regression output layers. How do I overcome this. I analyzed the structure of this network, and it is quite similar to mine, but the code which gave me an error previously runs fine when I use that pretrained network. What changes can I make to my network so it doesn't give me these errors?

  0 Comments

Sign in to comment.

1 Answer

Answer by Joss Knight
on 2 Feb 2019
 Accepted Answer

You have a DAGNetwork which means you cannot pass a layer index into activations, you have to pass a name:
res = activations(net,inputImage,net.Layers(numLayers-1).Name,'OutputAs','channels');

  4 Comments

Show 1 older comment
It just replaces the call to activations that you are currently making that is erroring.
It looks like maybe denoiseImage is a function that comes with the doc example? You're going to have to edit it to fix that line, because, presumably, it was written for a SeriesNetwork and you've passed it a DAGNetwork.
I've gotten around it by using the predict function for DAGNetworks, however the training process still gives an absurdly high RMSE. I've since turned to using the network architecture that the dnCNNLayers function returns, and I've gotten solid results with removing Gaussian noise from images. Now, I am trying to train it to remove Poisson type of noise, and I am having real trouble. Should I ask another question, or is it ok to try and resolve it in the comments?
You should ask another question, because your question is now concerned with domain knowledge in Deep Learning and Computer Vision, rather than just MATLAB syntax, for which there are other, much more appropriate people to help!

Sign in to comment.