How to train CNN with an image in the input and an image in the output?

조회 수: 102 (최근 30일)
I have a task to train CNN with an image as input and an image as output. I have tried to do it at the beginning with Matlab tutorial, but matlab has no image as output, but a vector.
any idea how i can do this tutorial again but with image as output?
For example you could insert input as image for number one and the output is also for number one but rotated or deformed.
Please don't send me other people's question, because i have seen all answers about it.
  댓글 수: 6
Osama Tabbakh
Osama Tabbakh 2020년 8월 15일
Hello Ritesh,
Unfortunately I haven't done it in Python yet. But I wish you all the best with it, good luck.
Florent Busnoult
Florent Busnoult 2020년 8월 25일
편집: Florent Busnoult 2020년 8월 25일
There is an example in the 5G toolbox that uses a CNN network with a picture as an input and a picture as an output.
The variable used to store the "labels" or (ouput images) is the following:
trainLabels(:,:,:,i) = est_grid;
It's a 4-D double variable.
And you can look at the different output images used to trian the network by using the command below:
>> imagesc(abs(trainLabels(:,:,:,2))); % output image number 2
>> imagesc(abs(trainLabels(:,:,:,3))); % output image number 3
>> imagesc(abs(trainLabels(:,:,:,25))); % output image number 25
and so on.

댓글을 달려면 로그인하십시오.

채택된 답변

Vasilis Giannoglou
Vasilis Giannoglou 2020년 9월 16일
I was also struggling with having an image as an output and I found the solution. Skip the fullyConnectedLayer(n) part, because it causes the network to have an output of either a vector or just a number. However, make sure not to include any Pooling layers if you want your output to be of the same size as your input, because they cause downsampling. Finally, keep in mind that the number of filters of your final conv network is the same number as the 3rd dimension of your output image. For example,
convolution2dLayer(3,1,'Padding','same') gives an output image of (M,N,1), where M,N are the rows and columns of the initial image. The next code runs to me.
layers = [
imageInputLayer([64 64 1]) % My initial image is 64x64
convolution2dLayer(3,8,'Padding','same')
batchNormalizationLayer
reluLayer
% averagePooling2dLayer(2,'Stride',1) % Don't want this
convolution2dLayer(3,16,'Padding','same')
batchNormalizationLayer
reluLayer
% averagePooling2dLayer(2,'Stride',1) % Don't want this
convolution2dLayer(3,32,'Padding','same')
batchNormalizationLayer
reluLayer
convolution2dLayer(3,1,'Padding','same') % Because my initial image 3rd dimension is one.
batchNormalizationLayer
reluLayer
dropoutLayer(0.2)
% fullyConnectedLayer(10) % Don't want this
regressionLayer];
  댓글 수: 2
mary john
mary john 2022년 5월 20일
I tried to do this and gets an error with the regression layer. It states that the ''output size does not match response size", when I use the deep network designer.
Can you please help me to solve. Thanks in advance

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Johanna Pingel
Johanna Pingel 2019년 4월 29일
  댓글 수: 3
supriya Naik
supriya Naik 2020년 8월 28일
Did you get the solution sir?? Actually I am facing same problem now.
Osama Tabbakh
Osama Tabbakh 2020년 9월 17일
Yes, please see the accepted answer

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Image Data Workflows에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by